插值表达式和v-cloak
[v-cloak]{
display:none
}
...
<div v-cloak>{{msg}}</div>
v-html
v-pre
跳过数据渲染
v-text
单向文本渲染
v-once
数据渲染不可更改
案例:v-text v-once综合使用
<template>
<div>
<ul>
<li v-for="item in list" v-once v-text="item"></li>
</ul>
<el-button type="primary" @click="handle">+1</el-button>
<el-button type="primary" @click="handle2">+1响应式</el-button>
</div>
</template>
<script>
export default {
name: 'App',
data(){
return {
list:[1,2,3,4,5]
}
},
methods:{
handle(){
this.list[0]=0
console.log(this.list);
},
handle2(){
this.$set(this.list,5,100)
console.log(this.list);
}
}
}
</script>
<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>
v-bind 或 :
单向属性渲染
比如:处理类名 或 处理style样式
类名以对象形式
.red{
background-color:red
}
...
<div v-bind:class="{red:true/false}"></div>
类名以数组形式
.red{
background-color:red
}
.green{
background-color:green
}
...
<div v-bind:class="[red,green]"></div>
v-model
双向渲染
v-on或@
进行事件监听
另外还有事件修饰符
stop阻止冒泡
prevent阻止默认行为等