1
이름을 표시하는 구성 요소가 있습니다. 각 이름의 글자 수를 계산해야합니다. nameLength
을 계산 된 속성으로 추가했지만 vuejs는 루프에서이 속성을 확인하지 않습니다.Vuejs2 - 구성 요소의 계산 된 속성
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
고맙습니다. 하드 킨,하지만 jsfiddle 예제가 작동하지 않습니다. – maxxdev
http://jsfiddle.net/6vhjq11v/5/ 이것을 유감스럽게 생각합니다. 그 것을 잊어 버리 셨습니다. –
감사합니다. 예상대로 잘 작동하는 방법으로 길이를 계산 해 주셔서 감사합니다. if interesting이 존재한다면 계산 된 결과를 사용할 수 있습니다. 예 : https://vuejs.org/guide/computed.html#Computed-vs-Watched-Property FullName ... – maxxdev