【发布时间】:2017-10-31 20:16:56
【问题描述】:
虽然我在文档中找不到,但改变数据数组属性似乎不是一个好主意,即使它没有被渲染到视图中。
看到这个小提琴:https://jsfiddle.net/078v5142/3/
我需要减少conditionalSet。我在每个 v-for 循环上使用 pop() 来检查索引的条件。我不能使用计算属性,因为我需要传递索引。
我也不能只复制conditionalSet 数组,因为在设置和弹出条件时需要对其进行跟踪。
这是我面临的一个大大简化的问题。
new Vue({
el: '#app',
data: {
message: 'Hello Vue.js! I do not like loops, all that much.',
imageSet: [
'a','b','c','d','e','f','g', 'h', 'i', 'j'
],
conditionalSet: [1,2]
},
methods: {
doShow(index){
if(this.someInnerConditionThatsNotRenderedOut()){
if( index === 1 || index === 4 || index === 5 || index === 6){
this.conditionalSet.pop(); // <-- this is the problem, but how to I track?
return true;
}
}
console.log('I should no show index 5 and index 6')
},
someInnerConditionThatsNotRenderedOut(){
return true //comment this out. No error.
return this.conditionalSet.length > 0
}
}
})
【问题讨论】:
标签: javascript vuejs2