Skip to content

Commit c62d238

Browse files
wip(tests): update
1 parent 3501d21 commit c62d238

File tree

1 file changed

+96
-34
lines changed

1 file changed

+96
-34
lines changed

test/vue3.html

Lines changed: 96 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,64 +2,126 @@
22
<html>
33
<body>
44
<script src="https://unpkg.com/vue@next/dist/vue.runtime.global.prod.js"></script>
5-
<script src="https://unpkg.com/vue-i18n@next"></script>
65
<script src="vue3-sfc-loader.js"></script>
76
<script>
87

98
/* <!-- */
109
const config = {
1110
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': `
1314
<template>
14-
<span class="vue3">{{ $t('hello') }}</span>
15+
<mycomponent
16+
:name="'circle' + index % 2"
17+
/>
1518
</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+
},
1936
}
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+
2849
}
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+
`
3275
}
3376
};
3477
/* --> */
3578

36-
const i18n = VueI18n.createI18n();
37-
3879
const options = {
3980
moduleCache: { vue: Vue },
4081
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) {
5083

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);
5496
}
5597
}
5698

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>
58114
59-
app.use(i18n);
115+
const options = {
116+
moduleCache: { vue: Vue },
117+
getFile: () => `<template>Hello World !</template>`,
118+
addStyle: () => {},
119+
}
60120
61-
app.mount(document.body);
121+
Vue.createApp(Vue.defineAsyncComponent(() => window['vue3-sfc-loader'].loadModule('file.vue', options))).mount(document.body);
62122
63123
</script>
64124
</body>
65125
</html>
126+
127+
-->

0 commit comments

Comments
 (0)