Vue其他常用指令

Vue其他常用指令

v-bind:将变量中的值通过v-bind绑定到元素指定的属性

eg:v-bind:style v-bind:class

v-bind也支持简写(v-on:相当于 :)

v-show:v-show=“表达式” ,根据表达式执行的结果的真假,来切换display显示还是隐藏

v-text:v-text=“变量”,根据变量更新对应的文本内容

v-html:v-html=“变量”,根据变量更新对应的innerHTML

例子:

<body>
    <div id="container">
        <h1>{{msg}}</h1>
        <!-- v-bind实现将变量中值  绑定到属性 -->
        <img v-bind:src="'img/'+imgUrl" width=50px height=50px>
        <a v-bind:href="myLink">tiaozhuan</a>

        <button v-on:click="modifyBGColor">修改背景色</button>
        <h1 v-bind:style="{backgroundColor:myBGColor}">背景色会被修改</h1>

        <p v-bind:class="{myRed:isRed}">我的字体会变颜色</p>

        <button v-bind:disabled="!isValid">clickMe</button>

        <button v-show="hasMore">加载更多</button>
        <p v-show="!hasMore">没有更多的数据可以加载</p>

        <div v-html="myHtml"></div>
    </div>

    <script>
        new Vue({
            el: "#container",
            data: {
                msg: '麻子',
                imgUrl: '1.jpg',
                myLink: 'http://www.baidu.com',
                myBGColor: "#ff0000",
                isRed: false,
                isValid: false,
                hasMore: true,
                myHtml: "<h1>我是麻子</h1>"
            },
            methods: {
                modifyBGColor: function () {
                    this.myBGColor = "#0000ff"
                }
            }
        })
    </script>
</body>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值