2
2
< html >
3
3
< body >
4
4
< script src ="https://unpkg.com/vue@next/dist/vue.runtime.global.prod.js "> </ script >
5
- < script src ="https://unpkg.com/vue-i18n@next "> </ script >
6
5
< script src ="vue3-sfc-loader.js "> </ script >
7
6
< script >
8
7
9
8
/* <!-- */
10
9
const config = {
11
10
files : {
12
- '/component.vue' : `
11
+ '/circle0.svg' : `<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"><circle cx="50" cy="50" r="50" /></svg>` ,
12
+ '/circle1.svg' : `<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"><circle cx="50" cy="50" r="40" /></svg>` ,
13
+ '/main.vue' : `
13
14
< template >
14
- <span class="vue3">{{ $t('hello') }}</span>
15
+ < mycomponent
16
+ :name = "'circle' + index % 2"
17
+ / >
15
18
</template >
16
- <style scoped>
17
- .vue3 {
18
- background: red;
19
+ < script >
20
+ import mycomponent from './myComponent.vue'
21
+ import { ref } from 'vue'
22
+
23
+ export default {
24
+ components : {
25
+ mycomponent
26
+ } ,
27
+ setup() {
28
+
29
+ const index = ref ( 0 ) ;
30
+ setInterval ( ( ) => index . value ++ , 1000 ) ;
31
+
32
+ return {
33
+ index,
34
+ }
35
+ } ,
19
36
}
20
- </style>
21
- <i18n>
22
- {
23
- "en": {
24
- "hello": "hello world!"
25
- },
26
- "ja": {
27
- "hello": "こんにちは、世界!"
37
+ </ script >
38
+ `,
39
+ '/myComponent.vue': `
40
+ < template >
41
+ < span v-html ="svg " />
42
+ </ template >
43
+ < script >
44
+
45
+ import { ref , watch } from 'vue'
46
+
47
+ class test {
48
+
28
49
}
29
- }
30
- </i18n>
31
- `
50
+
51
+ console . log ( test )
52
+
53
+ function asyncToRef ( callback ) {
54
+
55
+ const val = ref ( ) ;
56
+ watch ( ( ) => callback ( ) , promise => promise . then ( value => val . value = value ) , { immediate : true } ) ;
57
+ return val ;
58
+ }
59
+
60
+ export default {
61
+ props : {
62
+ name : String
63
+ } ,
64
+ setup ( props ) {
65
+
66
+
67
+ return {
68
+ svg : asyncToRef ( ( ) => import ( './' + ( props . name ?? '' ) + '.svg' ) ) ,
69
+ }
70
+ }
71
+ }
72
+
73
+ </ script >
74
+ `
32
75
}
33
76
};
34
77
/* --> */
35
78
36
- const i18n = VueI18n . createI18n ( ) ;
37
-
38
79
const options = {
39
80
moduleCache: { vue: Vue },
40
81
getFile: url => config.files[url],
41
- addStyle : ( textContent ) => {
42
- const style = Object . assign ( document . createElement ( 'style' ) , { textContent } ) ;
43
- const ref = document . head . getElementsByTagName ( 'style' ) [ 0 ] || null ;
44
- document . head . insertBefore ( style , ref ) ;
45
- } ,
46
- customBlockHandler ( block , filename , options ) {
47
-
48
- if ( block . type !== 'i18n' )
49
- return
82
+ addStyle(textContent) {
50
83
51
- const messages = JSON . parse ( block . content ) ;
52
- for ( let locale in messages )
53
- i18n . global . mergeLocaleMessage ( locale , messages [ locale ] ) ;
84
+ const style = Object.assign(document.createElement('style'), { textContent });
85
+ const ref = document.head.getElementsByTagName('style')[0] || null;
86
+ document.head.insertBefore(style, ref);
87
+ },
88
+ handleModule: async function (type, getContentData, path, options) {
89
+ switch (type) {
90
+ case '.svg':
91
+ return getContentData(false);
92
+ }
93
+ },
94
+ log(type, ...args) {
95
+ console[type](...args);
54
96
}
55
97
}
56
98
57
- const app = Vue . createApp ( Vue . defineAsyncComponent ( ( ) => window [ 'vue3-sfc-loader' ] . loadModule ( '/component.vue' , options ) ) ) ;
99
+ Vue.createApp(Vue.defineAsyncComponent(() => window['vue3-sfc-loader'].loadModule('/main.vue', options))).mount(document.body);
100
+
101
+ </ script >
102
+ </ body >
103
+ </ html >
104
+
105
+ <!--
106
+
107
+
108
+ <!DOCTYPE html>
109
+ <html>
110
+ <body>
111
+ <script src="https://unpkg.com/vue@next/dist/vue.runtime.global.prod.js"></script>
112
+ <script src="vue3-sfc-loader.js"></script>
113
+ <script>
58
114
59
- app . use ( i18n ) ;
115
+ const options = {
116
+ moduleCache: { vue: Vue },
117
+ getFile: () => `<template>Hello World !</template>`,
118
+ addStyle: () => {},
119
+ }
60
120
61
- app . mount ( document . body ) ;
121
+ Vue.createApp(Vue.defineAsyncComponent(() => window['vue3-sfc-loader'].loadModule('file.vue', options))) .mount(document.body);
62
122
63
123
</script>
64
124
</body>
65
125
</html>
126
+
127
+ -->
0 commit comments