Vue基础指令

插值表达式和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阻止默认行为等

v-if 或 v-else

v-show

v-for 和 :key

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值