Skip to content

Commit c8887d6

Browse files
committed
chore: update docs for v4
1 parent bc4c76c commit c8887d6

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

Diff for: README.md

+23-22
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Vue SFC REPL as a Vue 3 component.
44

55
## Basic Usage
66

7-
**Note: 2.0 now supports Monaco Editor, but also requires explicitly passing in the editor to be used for tree-shaking.**
7+
**Note: `@vue/repl` >= 2 now supports Monaco Editor, but also requires explicitly passing in the editor to be used for tree-shaking.**
88

99
### With CodeMirror Editor
1010

@@ -46,41 +46,42 @@ Customize the behavior of the REPL by manually initializing the store.
4646

4747
```vue
4848
<script setup>
49-
import { watchEffect } from 'vue'
50-
import { Repl, ReplStore } from '@vue/repl'
49+
import { watchEffect, ref } from 'vue'
50+
import { Repl, useStore, useVueImportMap } from '@vue/repl'
5151
import Monaco from '@vue/repl/monaco-editor'
5252
5353
// retrieve some configuration options from the URL
5454
const query = new URLSearchParams(location.search)
5555
56-
const store = new ReplStore({
57-
// initialize repl with previously serialized state
58-
serializedState: location.hash.slice(1),
59-
60-
// starts on the output pane (mobile only) if the URL has a showOutput query
61-
showOutput: query.has('showOutput'),
62-
// starts on a different tab on the output pane if the URL has a outputMode query
63-
// and default to the "preview" tab
64-
outputMode: query.get('outputMode') || 'preview',
65-
56+
const { importMap: builtinImportMap, vueVersion } = useVueImportMap({
6657
// specify the default URL to import Vue runtime from in the sandbox
6758
// default is the CDN link from jsdelivr.com with version matching Vue's version
6859
// from peerDependency
69-
defaultVueRuntimeURL: 'cdn link to vue.runtime.esm-browser.js',
60+
runtimeDev: 'cdn link to vue.runtime.esm-browser.js',
61+
runtimeProd: 'cdn link to vue.runtime.esm-browser.prod.js',
62+
serverRenderer: 'cdn link to server-renderer.esm-browser.js',
7063
})
7164
65+
const store = useStore(
66+
{
67+
// pre-set import map
68+
builtinImportMap,
69+
vueVersion,
70+
// starts on the output pane (mobile only) if the URL has a showOutput query
71+
showOutput: ref(query.has('showOutput')),
72+
// starts on a different tab on the output pane if the URL has a outputMode query
73+
// and default to the "preview" tab
74+
outputMode: ref(query.get('outputMode') || 'preview'),
75+
},
76+
// initialize repl with previously serialized state
77+
location.hash,
78+
)
79+
7280
// persist state to URL hash
7381
watchEffect(() => history.replaceState({}, '', store.serialize()))
7482
75-
// pre-set import map
76-
store.setImportMap({
77-
imports: {
78-
myLib: 'cdn link to esm build of myLib',
79-
},
80-
})
81-
8283
// use a specific version of Vue
83-
store.setVueVersion('3.2.8')
84+
vueVersion.value = '3.2.8'
8485
</script>
8586
8687
<template>

0 commit comments

Comments
 (0)