-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
45 lines (43 loc) · 1.12 KB
/
index.html
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
37
38
39
40
41
42
43
44
45
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Markdown in the browser</title>
<link rel="stylesheet" href="./css/index.css">
</head>
<body>
<div id="app">
<textarea v-model="message" name="textarea" id="textarea" cols="30" rows="10"></textarea>
<div id="content" v-html="markedMessage"></div>
</div>
<script src="./js/vue.js"></script>
<script src="./js/marked.js"></script>
<script>
var app = new Vue({
el: '#app',
data: {
message: '<h2 style="color:red;">hello world</h2></br> 你可以使用html语法来书写markdown啦!',
markedMessage: ''
},
watch: {
message: {
handler: function (val, oldVal) {
if (val !== oldVal) {
this.markedMessage = this.rendarHtml(marked(this.message));
}
},
deep: true,
immediate: true
}
},
methods: {
rendarHtml(text){
let content = document.getElementById('content')
content.innerHTML=`${text}`
document.body.appendChild(content)
}
}
})
</script>
</body>
</html>