<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vue模版语法</title>
<script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.12/vue.min.js"></script>
</head>
<body>
<div id="demo">
<!-- 文本 -->
<div>{{myHtml}}</div>
<!-- 原始Html -->
<div v-html="myHtml"></div>
<!-- 属性绑定 -->
<a v-bind:href="myUrl">跳转到{{myUrl}}</a>
<!-- 事件绑定 -->
<div v-on:click="foo">点击更改跳转路径</div>
<!-- JavaScript表达式 -->
<div>{{1+1}}</div>
<div>{{number+1}}</div>
<div>{{flag?"正确🙆♂️":"错误🙅♂️"}}</div>
<div v-on:click="changeFlag">点击更改flag{{flag}}</div>
</div>
</body>
<script>
var vm = new Vue({
el: "#demo",
data: {
myHtml: "<h1>一级标题</h1>",
myUrl: "https://baidu.com",
number: 5,
flag:true,
},
methods: {
foo() {
this.myUrl = "https://taobao.com";
},
changeFlag(){
this.flag = !this.flag;
},
}
})
</script>
</html>
最后得到绑定的示例演示
分析代码理解
文本作对比
点击跳转则跳转 点击更改则显示处更改