Vue從零開始總結8
{{內容}}里面的內容不僅可以是data中的變量也可以是methods里面的函數(shù)寫的時候這樣
<h2>{{getFullName()}}</h2>
data:{
firstName:'徐',
lastName:'文立'
}
methods:{
getFullName:function ()
{
? ?return this.firstName+' '+this.lastName;
}
}
就算是這樣看起來也不是很簡潔,還是很難做到見名知意的程度
這時候我們就需要用到計算屬性了,也就是computed:{}
computed中一切皆屬性,哪怕你里面寫的是函數(shù),寫出來也是這樣的
<h2>{{fullName}}</h2>
computed:{
? ?fullName:function ()
? ?{
? ? ? ?return this.firstName+this.lastName;
? ?}
}
最后注意的是computed與el,data,methods是并列的
標簽: