我认为你要对标题进行过滤的话直接把过滤器设置在每一个商品上比较好,没必要对整个全部进行过滤处理,比如我这样。也能实现业务场景。至于你的代码的错误,我不太懂明白为什么在computed里定义methods,我也刚开始学,如果可以给下源码,也想看看你的方法错在哪
- {{good.title}}
export default {
data () {
return {
// note: changing this line won't causes changes
// with hot-reload because the reloaded component
// preserves its current state and we are modifying
// its initial state.
msg: 'Hello World!',
searchGood: '',
items: [
{message: 'Foo'},
{message: 'Bar'}
],
arrs: [
{
goods: [{
title: 'A标题'
}, {
title: 'B标题'
}, {
title: '这是标题'
}],
orderNo: '111111111111',
showtr: true
},
{
goods: [{
title: 'AA标题'
}, {
title: 'BB标题'
}],
orderNo: '222222222222',
showtr: true
}]
}
},
methods: {
goodFilter (good) {
if (this.searchGood === '') {
return true
}
if (good.title.indexOf(this.searchGood) !== -1) {
return true
} else {
return false
}
}
}
}
h1 {
color: #42b983;
}