【发布时间】:2016-11-03 14:06:34
【问题描述】:
我有一个显示名称的组件。我需要计算每个名字的字母数。
我添加了nameLength 作为计算属性,但是 vuejs 并没有在循环中确定这个属性。
var listing = Vue.extend({
template: '#users-template',
data: function () {
return {
query: '',
list: [],
user: '',
}
},
computed: {
computedList: function () {
var vm = this;
return this.list.filter(function (item) {
return item.toLowerCase().indexOf(vm.query.toLowerCase()) !== -1
})
},
nameLength: function () {
return this.length; //calculate length of current item
}
},
created: function () {
this.loadItems();
},
methods: {
loadItems: function () {
this.list = ['mike','arnold','tony']
},
}
});
http://jsfiddle.net/apokjqxx/22/
所以结果是预期的
麦克-4
阿诺德-6
tony-4
【问题讨论】:
标签: computed-properties vuejs2