首页 > 其他 > 详细

v-bind

时间:2018-07-30 19:50:46      阅读:168      评论:0      收藏:0      [点我收藏+]
  • v-bind:class 可以简写成 :class
    <span v-bind:class="color">{{title}}</span>
    
    data: {
        title: ‘Welcome to duyi!!!‘,
        color: ‘red‘
    }

 


  • 对象
  • :class = {} class 的值由 key 组成, 但是由value决定
    .red{
        color: red;
    }
    .font{
        font-size: 30px;
    }
    <span :class="{red,font}">{{title}}</span>
    data: {
        red: true,
        font: true
    }
    <span v-bind:class="cssObject">{{title}}</span>
    data: {
        color: ‘red‘,
        cssObject: {
            red: true,
            font: true,
        }
    }

 


  • 数组
  • :class = [] class 是由数组中每一项对应的值决定
    .red{
        color: red;
    }
    .font{
        font-size: 30px;
    }
    <span v-bind:class="[fontSize, color]">{{title}}</span>
    data: {
        fontSize: ‘font‘,
        color: ‘red‘
    }
    .red{
        color: red;
    }
    .font{
        font-size: 30px;
    }
    <span v-bind:class="styleObj">{{title}}</span>
    data: {
        color: ‘red‘,
        styleObj: [‘font‘,‘red‘]
    }

 


:style

    <span :style="{color}">{{title}}</span>
    data: {
        color: ‘red‘
    }
    <span :style="[style1,style2]">{{title}}</span>
    data: {
        style1: {
            color: ‘green‘
        },
        style2: {
            fontWeight: 600
        }
    }

 


:type

    <input :type="type">
    data: {
        type: ‘text‘
    }

 


v-model 双向数据绑定

    <input :type="type" v-model=‘title‘>
    <div>{{title}}</div>
    data: {
        title: ‘Welcome to duyi!!!‘,
        type: ‘text‘
    }

 

模拟 v-model

    <input :type="text" v-model=‘title‘>
    <br>
    <input type="text" :value=‘title‘ @input="e=>title = e.target.value">
    <div>{{title}}</div>
    data: {
        title: ‘模拟v-model‘
    }

 

v-bind

原文:https://www.cnblogs.com/goff-mi/p/9392332.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!