vue学习笔记(五)——指令
2017-03-22 20:28
435 查看
13条指令
1. v-text (数据绑定语法-插值)
2.v-html (数据绑定语法-插值,普通HTML,注意安全)
3.v-show (条件渲染,触发过渡效果)
4.v-if (条件渲染)
5.v-else (条件渲染)
6.v-else-if (条件渲染)
7.v-for (列表渲染)
8.v-on (绑定事件监听器)
9.v-bind (动态绑定,class,style,props)
10.v-model (表单控件绑定, input, select, textarea, lazy, number, trim)
11.v-pre (跳过编译过程)
12.v-cloak (这个指令保持在元素上直到关联实例结束编译。)
13.v-once (数据绑定-插值,用于优化更新性能)
1. v-text (数据绑定语法-插值)
<span v-text="msg"></span> <!-- 和下面的一样 --> <span>{{msg}}</span>
2.v-html (数据绑定语法-插值,普通HTML,注意安全)
<div v-html="html"></div>
3.v-show (条件渲染,触发过渡效果)
<h1 v-show="ok">Hello!</h1>
4.v-if (条件渲染)
5.v-else (条件渲染)
<div v-if="Math.random() > 0.5"> Now you see me </div> <div v-else> Now you don't </div>
6.v-else-if (条件渲染)
<div v-if="type === 'A'"> A </div> <div v-else-if="type === 'B'"> B </div> <div v-else-if="type === 'C'"> C </div> <div v-else> Not A/B/C </div>
7.v-for (列表渲染)
<div v-for="item in items"> {{ item.text }} </div> //也可以为数组索引指定别名(或者用于对象的键): <div v-for="(item, index) in items"></div> <div v-for="(val, key) in object"></div> <div v-for="(val, key, index) in object"></div> //迫使其重新排序的元素,您需要提供一个 key 的特殊属性: <div v-for="item in items" :key="item.id"> {{ item.text }} </div>
8.v-on (绑定事件监听器)
<!-- 方法处理器 --> <button v-on:click="doThis"></button> <!-- 内联语句 --> <button v-on:click="doThat('hello', $event)"></button> <!-- 缩写 --> <button @click="doThis"></button> <!-- 停止冒泡 --> <button @click.stop="doThis"></button> <!-- 阻止默认行为 --> <button @click.prevent="doThis"></button> <!-- 阻止默认行为,没有表达式 --> <form @submit.prevent></form> <!-- 串联修饰符 --> <button @click.stop.prevent="doThis"></button> <!-- 键修饰符,键别名 --> <input @keyup.enter="onEnter"> <!-- 键修饰符,键代码 --> <input @keyup.13="onEnter"> <!--在子组件上监听自定义事件(当子组件触发 “my-event” 时将调用事件处理器)--> <my-component @my-event="handleThis"></my-component> <!-- 内联语句 --> <my-component @my-event="handleThis(123, $event)"></my-component> <!-- 组件中的原生事件 --> <my-component @click.native="onClick"></my-component>
9.v-bind (动态绑定,class,style,props)
<!-- 绑定一个属性 --> <img v-bind:src="imageSrc"> <!-- 缩写 --> <img :src="imageSrc"> <!-- with inline string concatenation --> <img :src="'/path/to/images/' + fileName"> <!-- class 绑定 --> <div :class="{ red: isRed }"></div> <div :class="[classA, classB]"></div> <div :class="[classA, { classB: isB, classC: isC }]"> <!-- style 绑定 --> <div :style="{ fontSize: size + 'px' }"></div> <div :style="[styleObjectA, styleObjectB]"></div> <!-- 绑定一个有属性的对象 --> <div v-bind="{ id: someProp, 'other-attr': otherProp }"></div> <!-- 通过 prop 修饰符绑定 DOM 属性 --> <div v-bind:text-content.prop="text"></div> <!-- prop 绑定. “prop” 必须在 my-component 中声明。 --> <my-component :prop="someThing"></my-component> <!-- XLink --> <svg><a :xlink:special="foo"></a></svg>
10.v-model (表单控件绑定, input, select, textarea, lazy, number, trim)
<input v-model="message" placeholder="edit me"> <p>Message is: {{ message }}</p>
11.v-pre (跳过编译过程)
<span v-pre>{{ this will not be compiled }}</span>
12.v-cloak (这个指令保持在元素上直到关联实例结束编译。)
[v-cloak] { display: none; } <div v-cloak> {{ message }} </div>
13.v-once (数据绑定-插值,用于优化更新性能)
<!-- 单个元素 --> <span v-once>This will never change: {{msg}}</span> <!-- 有子元素 --> <div v-once> <h1>comment</h1> <p>{{msg}}</p> </div> <!-- 组件 --> <my-component v-once :comment="msg"></my-component> <!-- v-for 指令--> <ul> <li v-for="i in list" v-once>{{i}}</li> </ul>
相关文章推荐
- Vue学习笔记——指令和部分组件
- Vue.js第一天学习笔记(数据的双向绑定、常用指令)
- vue 学习笔记 part-4 ->v-on指令
- vue 学习笔记 part-2->指令v-for
- Vue.js第一天学习笔记(数据的双向绑定、常用指令)
- 5.3.vue入门基础学习笔记-基础指令介绍(属性绑定v-bind)
- vue 学习笔记 part-3 -> v-bind指令
- vue学习笔记之指令v-text && v-html && v-bind详解
- Vue.js学习笔记:在元素 和 template 中使用 v-if 指令
- vue学习笔记2——指令v-text && v-html && v-bind
- Vue.js学习笔记:在元素 和 template 中使用 v-if 指令
- 汇编语言学习笔记18086指令系统
- 80X86学习笔记--数据传送指令
- ARM指令---学习笔记
- FPGA学习笔记7-Quartus II其余的部分TCL指令
- 80X86学习笔记--转移指令
- 王爽《汇编语言》(第二版) 学习笔记 (第九章 转移指令的原理 )
- freemaker学习笔记--指令参考
- 80X86学习笔记--数据传送指令
- 8086汇编学习笔记4-指令