我正在尝试使用 Vuex 和 Vuetify 为搜索框异步填充下拉列表(https://vuetifyjs.com/components/selects)。我的问题是我无法使用方法()访问 $store,当然只能使用计算()。
这是我的吸气剂/状态:
loadedTours:Array[9]
0:Object
1:Object
2:Object
3:Object
4:Object
5:Object
6:Object
7:Object
8:Object
9:Object
Run Code Online (Sandbox Code Playgroud)
可以从计算()中使用 v-for 返回
tours () {
return this.$store.getters.loadedTours
},
Run Code Online (Sandbox Code Playgroud)
这是一个仅当列表在 data() 中时才有效的方法():
methods: {
querySelections (v) {
this.loading = true
setTimeout(() => {
this.items = this.tours.filter(e => {
return (e || '').toLowerCase().indexOf((v || '').toLowerCase()) > -1
})
this.loading = false
}, 500)
}
}
Run Code Online (Sandbox Code Playgroud)
结果应返回每个对象中列出的旅游标题。
当前解决方案:
添加了创建():
created () {
this.loadedTours = this.$store.getters.loadedTours
},
Run Code Online (Sandbox Code Playgroud)
将方法()更改为:
querySelections (v) {
let that …Run Code Online (Sandbox Code Playgroud)