Vue Code Demo
Mr.Hope ... 2021-8-26 Less than 1 minute
# Syntax
::: vue-demo Optional title text
```vue
<!-- ↑ You can also use `html` -->
<template>
<!-- vue template -->
</template>
<script>
export default {
// vue component
};
</script>
<style>
/* css code */
</style>
```
```json
// Config (Optional)
```
:::
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Attention
- We only support Vue2
- You must export your component through
export default
- We use "ShadowDOM" to make style isolation, and we already replace
document
withshadowRoot
. To access the page document, please visitwindow.document
.
# Demo
A Vue Composition Demo (Vue2.7+)
<template>
<div class="box">
<code>vuepress-theme-hope</code> is
<span @click="handler">{{ message }}</span
>!
</div>
</template>
<script>
const { ref } = Vue;
export default {
setup() {
const message = ref("powerful");
const handler = () => {
message.value = "very " + message.value;
};
return {
message,
handler,
};
},
};
</script>
<style>
.box span {
color: red;
}
</style>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Code
::: vue-demo A Vue Composition Demo (Vue2.7+)
```vue
<template>
<div class="box">
<code>vuepress-theme-hope</code> is
<span @click="handler">{{ message }}</span
>!
</div>
</template>
<script>
const { ref } = Vue;
export default {
setup() {
const message = ref("powerful");
const handler = () => {
message.value = "very " + message.value;
};
return {
message,
handler,
};
},
};
</script>
<style>
.box span {
color: red;
}
</style>
```
:::
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
A Vue Option Demo
<template>
<div class="box">
<code>vuepress-theme-hope</code> is
<span @click="handler">{{ message }}</span
>!
</div>
</template>
<script>
export default {
data: () => ({ message: "powerful" }),
methods: {
handler() {
this.message = "very " + this.message;
},
},
};
</script>
<style>
.box span {
color: red;
}
</style>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Code
::: vue-demo A Vue Option Demo
```vue
<template>
<div class="box">
<code>vuepress-theme-hope</code> is
<span @click="handler">{{ message }}</span
>!
</div>
</template>
<script>
export default {
data: () => ({ message: "powerful" }),
methods: {
handler() {
this.message = "very " + this.message;
},
},
};
</script>
<style>
.box span {
color: red;
}
</style>
```
:::
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28