v-bind特性



插值语法不能作用在 HTML 特性上,因此使用 v-bind 指令
1、v-bind在一般特性上的使用:如id,src,disabled,checked,selected,name

html:

1 <section id="content">
2     插值语法不能作用在 HTML 特性上,遇到这种情况应该使用 v-bind 指令
3     <p v-bind:id="pId">信息</p>
4     <img v-bind:src="icon" alt="婚纱">
5     v-bind:disabled【缩写::disabled】<br>
6     <button type="button" :disabled="isDisable">禁用</button>
7 </section>

js:

1 var vm = new Vue({
2         el:"#content",
3         data: {
4             pId:"info",
5             icon:"../imgs/cloth.png",
6             isDisable:true
7         }
8     });

渲染的结果:

 

2、v-bind在class ,style上的使用

A: class 上的使用

html:

 

<section id="content">
对象语法:<br>
    <span v-bind:class="{success:isSuccess}">当前状态是否正确</span>
    <span v-bind:class="{success:isSuccess,disabled:true}">当前状态是否正确</span>
    数组语法<br>
    <span v-bind:class="[stateClass]">当前状态是否正确</span>
    <span v-bind:class="[stateClass,{disabled:true}]">当前状态是否正确</span>
</section>

 

js:

 1 var vm = new Vue({
 2         el:"#content",
 3         data: {
 4             pId:"info",
 5             icon:"../imgs/cloth.png",
 6             isDisable:true,
 7             isSuccess:true,
 8             stateClass:"success"
 9         }
10     });

result:

 

 B: style的使用

html:

 

1 对象语法:<br />
2     <span v-bind:style="{color:activeColor}">当前状态是否正确</span>
3     <span v-bind:style="{color:activeColor,fontSize:'18px'}">当前状态是否正确</span><br>
4     数组语法<br />
5     <span v-bind:style="colorObject">当前状态是否正确</span>
6     <span v-bind:style="[colorObject,fontObject]">当前状态是否正确</span>

 

js:

 1 var vm = new Vue({
 2         el:"#content",
 3         data: {
 4             activeColor:"#009688",
 5             colorObject:{
 6                 color:"#009688"
 7             },
 8             fontObject:{
 9                 fontSize:"20px"
10             }
11         }
12     });

result:

 

posted @ 2018-01-04 18:28  钟离野  阅读(4293)  评论(0编辑  收藏  举报