我的Vue应用程序使用了firebase,我遇到了麻烦。我现在已经使快照正常工作并且正在接收我转换为数组的对象。唯一的问题是,当我尝试过滤对象时,我得到一个"无法读取属性" indexOf"未定义"该函数正常打印出阵列,并且看起来就像我需要的那样,我只能通过包含来访问它。值得一提的是,如果我输入0,1,2,3而不是i,它就不会抛出错误。
这是我的Vuex导出器,其中包含我的Firebase快照
const users = db.ref('users')
users.on('value', function (snapshot) {
store.state.lawyers = Object.values(snapshot.val())
console.log('called')
})
export const store = new Vuex.Store({
state: {
lawyers: '',
selectedLawyerIndex: 1,
selectedCategory: 'Contracts'
},
getters: {
getLawyers: state => {
console.log('state ' + state.lawyers)
return state.lawyers
},
getCurrentLawyer: state => {
return state.lawyers[state.selectedLawyerIndex]
}
}
和导致错误的函数:
export default {
data () {
return {
cat: this.$store.getters.getCurrentCategory,
lawyers: this.$store.getters.getLawyers
}
},
components: {
appLawyerWidget: LawyerWidget
},
methods: {
filteredLawyers () {
var arr = []
console.log(this.lawyers)
for (var i = 0; i < this.lawyers.length; i++) {
console.log(JSON.stringify(this.lawyers[i].catarray))
if (JSON.stringify(this.lawyers[i].catarray).indexOf(this.cat) >= 0) {
arr.push(i)
}
}
return arr
}
}
}
任何指针都会非常感激。谢谢!