Vue之v-bind

在Vue中,v-bind用于绑定html内容,可以简写为 格式为 v-bind:属性名=”…”
<a v-bind:href=”...”></a> = <a :href=”...”></a>
其中典型的属性是class和style,

<a v-bind:href="https://www.baidu.com">click here</a>

--->将会渲染成:

<a href="https://www.baidu.com">click here</a>
v-bind:class="{类名/css样式名:w}"
若w为真,则添加前面的类;若为假,则不添加
<style>
	.s{
		fontFamily:"宋体",
        color:'red',
        backgroundColor:'green'
       }
</style>
<p :class="{'s':isActive}">Hello World</p>
<script>
new Vue({
	el:"#demo",
	data:{
		isActive:true
		}
	});
</script>

v-bind:style="…"示例:

<h1 v-bind:style="cs">此处是显示特定的样式</h1>
<script>
    var cs={
        fontFamily:"宋体",
        color:'red',
        backgroundColor:'green'
    };
    cs.toString=function(){
        var str='';
        for(var i in this){
            str+=i+":"+this[i]+";";
        }
        return str;
    }
    var vm=new Vue({
        el:"#app",
        data:{
            cs:cs
        }
    });
</script>    

--->将被渲染成:

<h1 v-bind:style="fontFamily:'宋体'; color:'red';backgroundColor:'green' ">此处是显示特定的样式</h1>

使用函数的情况:

<div id="app">
    <p v-bind:title="getTitle()">html属性不能使用双大括号形式绑定,只能使用v-bind指令</p>
</div>
......
var vm = new Vue({
    el: "#app",
    data: {
        getTitle: function () {
            return "title content";
        }
    }
});
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值