mustache语法
<div id='app'>
<h2>{{message}}</h2>
<h2>{{message}}, 苦涩!</h2>
<!-- mustache语法中,不仅仅可以直接写变量,也可以写简单的表达式 -->
<h2>{{firstName + ' ' + lastName}}</h2>
<h2>{{firstName}} {{lastName}}</h2>
<!-- 计算 -->
<h2>{{counter * 2}}</h2>
</div>
<script>
const app = new Vue({
el: '#app',
data: {
message: 'hello',
firstName: "kuse",
lastName: "wang",
counter: 100
}
})
</script>
v-once
表示元素和组件只渲染一次,不会随着数据的变化而变化
<div id='app'>
<h2>{{message}}</h2>
<h2 v-once>{{message}}</h2>
</div>
<script>
const app = new Vue({
el: '#app',
data: {
message: 'hello',
}
})
</script>
v-html
将字符串中的HTML标签解析出来并且进行渲染
<div id='app'>
<h2>{{url}}</h2>
<h2 v-html = 'url'></h2>
</div>
<script>
const app = new Vue({
el: '#app',
data: {
message: 'hello',
url: "<a href='http://www.baidu.com'>百度一下</a>"
}
})
</script>
v-text
功能和mustache比较相似,但会将标签内的文本覆盖
<div id='app'>
<h2>{{message}}</h2>
<h2 v-text = 'message'></h2>
</div>
<script>
const app = new Vue({
el: '#app',
data: {
message: 'hello',
}
})
</script>
v-pre
用户跳过这个元素和它子元素的编译过程,用于显示原本的mustache语法
<div id='app'>
<h2>{{message}}</h2>
<h2 v-pre>{{message}}</h2>
</div>
<script>
const app = new Vue({
el: '#app',
data: {
message: 'hello',
}
})
</script>
v-cloak
在vue解析前,隐藏mustache语法
在vue解析后,显示mustache语法
<div id='app' v-cloak>
<h2>{{message}}</h2>
</div>
<script>
const app = new Vue({
el: '#app',
data: {
message: 'hello',
}
})
</script>