请教各位大神,最近再看Vue,写个小demo测试一下,但是不造怎么在Vue组件中使用计算属性、、、
computed 属性定义好了之后,正常使用就好了。
<div id="example"> a={{ a }}, b={{ b }} </div>
在使用上,a 和 b 没有区别。
var vm = new Vue({ el: '#example', data: { a: 1 }, computed: { // a computed getter b: function () { // `this` points to the vm instance return this.a + 1 } } })
而 b 是 computed 属性,a 是 普通属性 (data 里定义的)
https://vuejs.org/guide/computed.html
@leapon 嗯,这个我知道。我的意思是在自定义组件里面,怎么使用计算属性 var example-component = Vue.component({ data:function(){ return { a : '' } }, //我的意思是在这儿能使用computed吗?怎么用呢? });
var example-component = Vue.component({ data:function(){ return { a : '' } }, //我的意思是在这儿能使用computed吗?怎么用呢? });
var example-component = Vue.component( { data:function(){ return { a : ‘’ } , computed: { b: function () { return this.a + 1; } } }, });
@wangdashuaihenshuai 蟹蟹
CNode 社区为国内最专业的 Node.js 开源技术社区,致力于 Node.js 的技术研究。
computed 属性定义好了之后,正常使用就好了。
在使用上,a 和 b 没有区别。
而 b 是 computed 属性,a 是 普通属性 (data 里定义的)
https://vuejs.org/guide/computed.html
@leapon 嗯,这个我知道。我的意思是在自定义组件里面,怎么使用计算属性
var example-component = Vue.component({ data:function(){ return { a : '' } }, //我的意思是在这儿能使用computed吗?怎么用呢? });var example-component = Vue.component( { data:function(){ return { a : ‘’ } , computed: { b: function () { return this.a + 1; } } }, });
@wangdashuaihenshuai 蟹蟹