1
1
<template lang="html">
2
2
<div >
3
- <div class =" title" >
4
- @Vue3js.cn
5
- <button @click =" run" >运行一下</button>
6
- </div>
3
+
7
4
<div class =" example" >
8
5
<div class =" codemirror" >
9
6
<codemirror ref =" cmEditor" v-model =" code" :options =" cmOption" />
10
7
</div>
8
+ <div class =" title" >
9
+ @Vue3js.cn
10
+ <button @click =" run" >运行一下</button>
11
+ </div>
11
12
<div class =" result" >
12
13
<h3 >result:</h3>
13
14
<div id =" iframe" ></div>
17
18
</template >
18
19
19
20
<script >
21
+ import dedent from " dedent" ;
20
22
import { codemirror } from " vue-codemirror" ;
21
23
// base style
22
24
import " codemirror/lib/codemirror.css" ;
@@ -66,15 +68,38 @@ export default {
66
68
},
67
69
data () {
68
70
return {
69
- code: ` <!DOCTYPE html>\n <html>\n <head>\n <meta charset=\" utf-8\" >\n <title>Vue 测试33实例 - 菜鸟教程(runoob.com)</title>\n <script src=\" https://cdnjs.cloudflare.com/ajax/libs/vue/2.2.2/vue.min.js\" ></script>\n </head>\n <body>\n <div id=\" app\" >\n <p>原始字符串: {{ message }}</p>\n <p>计算后反转字符串: {{ reversedMessage }}</p>\n </div>\n\n <script>\n let vm = new Vue({\n el: '#app',\n data: {\n message: 'Runoob!'\n },\n computed: {\n // 计算属性的 getter\n reversedMessage: function () {\n return this.message.split('').reverse().join('')\n }\n }\n })\n </script>\n </body>\n </html>` ,
71
+ code: `
72
+ <!DOCTYPE html>
73
+ <html>
74
+ <head>
75
+ <meta charset="utf-8">
76
+ <title>Vue 测试实例</title>
77
+ <script src="https://doc.vue-js.com/js/vue.js">${ " </script>" }
78
+ </head>
79
+ <body>
80
+ <div id="app">
81
+ <p>{{ message }}</p>
82
+ </div>
83
+ <script>
84
+ new Vue({
85
+ el: '#app',
86
+ data: {
87
+ message: 'Hello Vue.js!'
88
+ }
89
+ })
90
+ ${ " </script>" }
91
+ </body>
92
+ </html>
93
+ ` ,
70
94
cmOption: {
71
95
tabSize: 4 ,
72
96
foldGutter: true ,
73
97
styleActiveLine: true ,
74
98
lineNumbers: true ,
75
99
line: true ,
76
100
keyMap: " sublime" ,
77
- mode: " text/x-vue" ,
101
+ mode: " text/html" ,
102
+ htmlMode: true ,
78
103
theme: " base16-dark" ,
79
104
extraKeys: {
80
105
F11 (cm ) {
@@ -85,7 +110,10 @@ export default {
85
110
}
86
111
}
87
112
}
88
- };
113
+ }
114
+ },
115
+ mounted () {
116
+ this .run ();
89
117
},
90
118
methods: {
91
119
run () {
@@ -158,16 +186,10 @@ export default {
158
186
border : none ;
159
187
}
160
188
.example {
161
- display : flex ;
162
189
height : 70vh ;
163
- background : #f7f7f7 ;
164
- padding : 30px ;
165
- border-radius : 15px ;
166
190
}
167
191
.codemirror ,
168
192
.result {
169
- width : 50% ;
170
- height : 100% ;
171
193
margin : 0 ;
172
194
overflow : auto ;
173
195
padding-top : 0 ;
@@ -180,7 +202,7 @@ export default {
180
202
word-break : break-all ;
181
203
word-wrap : break-word ;
182
204
}
183
- .result h3 {
205
+ .result h3 {
184
206
margin : 0 ;
185
207
}
186
- </style >
208
+ </style >
0 commit comments