@@ -4,7 +4,7 @@ Vue SFC REPL as a Vue 3 component.
4
4
5
5
## Basic Usage
6
6
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.**
8
8
9
9
### With CodeMirror Editor
10
10
@@ -46,41 +46,42 @@ Customize the behavior of the REPL by manually initializing the store.
46
46
47
47
``` vue
48
48
<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'
51
51
import Monaco from '@vue/repl/monaco-editor'
52
52
53
53
// retrieve some configuration options from the URL
54
54
const query = new URLSearchParams(location.search)
55
55
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({
66
57
// specify the default URL to import Vue runtime from in the sandbox
67
58
// default is the CDN link from jsdelivr.com with version matching Vue's version
68
59
// 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',
70
63
})
71
64
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
+
72
80
// persist state to URL hash
73
81
watchEffect(() => history.replaceState({}, '', store.serialize()))
74
82
75
- // pre-set import map
76
- store.setImportMap({
77
- imports: {
78
- myLib: 'cdn link to esm build of myLib',
79
- },
80
- })
81
-
82
83
// use a specific version of Vue
83
- store.setVueVersion( '3.2.8')
84
+ vueVersion.value = '3.2.8'
84
85
</script>
85
86
86
87
<template>
0 commit comments