zoukankan      html  css  js  c++  java
  • 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:

  • 相关阅读:
    IOS 网络编程 + 后台保持连接
    iOS 通过代码关闭应用程序
    iOS 委托和协议区别和联系
    对于WIFI版ipad(无GPS芯片)定位功能的释疑
    iOS单例
    svn不能添加.a文件的解决方法
    mac下SVN上传.a静态库文件
    iOS7 兼容及部分细节
    app被Rejected 的各种原因翻译
    iOS 沙盒购买,弹出“需要验证”,“继续登录”的问题?
  • 原文地址:https://www.cnblogs.com/lee90/p/8194980.html
Copyright © 2011-2022 走看看