名前を表示するコンポーネントがあります。各名前の文字数を計算する必要があります。計算されたプロパティとして追加しまし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
トニー-4