温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

vue.js绑定属性的示例

发布时间:2020-12-10 12:09:47 来源:亿速云 阅读:113 作者:小新 栏目:编程语言

这篇文章给大家分享的是有关vue.绑定属性的示例的内容。小编觉得挺实用的,因此分享给大家做个参考。一起跟随小编过来看看吧。

vue绑定属性的方法:1、class绑定,代码为【<li v-bind:class="'red'">item ---- key】;2、style绑定,代码为【<div class="box" v-bind:style="{heig...】。

vue绑定属性的方法:

1、属性绑定(2种方式)

<!-- 绑定属性 -->
<div v-bind:title="title">鼠标hover</div>
<div :title="title">鼠标悬浮</div>
<!-- 绑定地址 -->
<img v-bind:src="url" height="400" width="600"/>
<!-- html页面渲染 -->
<!-- 直接数据绑定 -->
<div>{{html}}</div>
<!-- 绑定html属性解析 -->
<div v-html="html"></div>
#js代码
<script>
    export default {
        name: 'app',
        data() {
            return {
                msg: 'vue demo',
                title: '这里是一个title',
                url: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1561705454&di=33c13bd9a15f514bae71aaf8250ff305&imgtype=jpg&er=1&src=http%3A%2F%2Fp3.ssl.qhimg.com%2Ft017c9d8f1ba39d313f.jpg',
                html:'<h4>我是HTML文本</h4>'
            }
        }
    }
</script>

2、数据绑定的另一种

<!-- text数据绑定 -->
<div v-text="msg"></div>

3、class绑定

#html
<div>
    <h4>div颜色列表</h4>
    <ul>
        <!-- 简单绑定class -->
        <li v-bind:class="'red'">
            item ---- key
        </li>
        <br/>
        <!-- 列表绑定 -->
        <li v-for="(item,key) in list" :class="{'red':key ==0,'blue':key==1,'green':key==2,'pink':key==3}">
            {{item}} ---- {{key}}
        </li>
    </ul>
</div>
#js代码
export default {
    name: 'app',
    data() {
        return {
            list: ['红色', '蓝色', '绿色', '粉色'],
        }
    }
}

4、style绑定

<!-- style绑定 -->
<div class="box" v-bind:style="{height:heightMax+'px',width:widthMax+'px'}">这里是一个div盒子</div>
#js代码
export default {
    name: 'app',
    data() {
        return {
             widthMax: 400,
             heightMax: 200,
        }
    }
}

感谢各位的阅读!关于vue.绑定属性的示例就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到吧!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI