v-once v-pre
v-once
:数据仅绑定一次
v-pre
:不编译,原样显示
举例如下:
<html>
<title>v-once v-pre</title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<body>
<div id="app">
<input type="text" v-model="msg">
<h2 v-once>{{msg}}</h2>
<h2 v-pre>{{msg}}</h2>
<h2>{{msg}}</h2>
</div>
<script>
var vm = new Vue({
el: "#app",
data: {
msg: "hello"
},
methods: {
}
});
</script>
</body>
</html>
带有v-once
标签的h2
显示"hello"字符串,但不会随着input框数据改变而改变
带有v-pre
标签的h2
则显示"{{msg}}“字符串,不会被编译为"hello”