<body>
<div id="app">
<h2>{{ message }} xdr630</h2>
<h2 v-text="message">xdr630</h2>
<h2 v-text="info">xdr630</h2>
</div>
<script src="../js/vue.js"></script>
<script>
const app = new Vue({
el: '#app',
data: {
message: 'hello,vue',
info: "你好,vue"
}
})
</script>
</body>
v-text
会覆盖元素中原来的内容,但是 插值表达式 ({{ }})
只会替换自己的这个占位符,不会把 整个元素 的内容给清空<h2>{{ message+'!!' }} xdr630</h2>
<h2 v-text="message+'!!'">xdr630</h2>
<h2 v-text="info+'!!'">xdr630</h2>
案例:v-text和v-html输入内容比较
<body>
<div id="app">
<p v-html="content"></p>
<p v-text="content"></p>
</div>
<script src="../js/vue.js"></script>
<script>
const app = new Vue({
el: '#app',
data: {
// content: "你好",
content: "<a href='https://xdr630.blog.csdn.net/' target='_blank'>兮动人</a>",
}
})
</script>
</body>
<body>
<div id="app">
<input type="button" value="v-on指令" v-on:click="doIt">
<input type="button" value="v-on简写" @click="doIt">
<input type="button" value="双击事件" @dblclick="doIt">
<h2 @click="changeFood">{{ food }}</h2>
</div>
<script src="../js/vue.js"></script>
<script>
const app = new Vue({
el: '#app',
data: {
food: "番茄炒鸡蛋"
},
methods: {
doIt: function () {
alert("做It");
},
changeFood: function () {
console.log(this.food)
this.food+="好好吃!";
}
}
})
</script>
</body>