报错TypeError: Cannot read properties of undefined (reading 'filter')
浏览器报错:TypeError: Cannot read properties of undefined (reading 'filter')
一开始写定了一个list数组一直没出错,后面换成pinia的数据就出问题了
原代码:
const list = computed(() => {
store.state.menuList
})
const noChildren = computed(() => list.value.filter(item => !item.children))
解决:
computed里放的store.state.menuList多环绕了一对大括号,于是它说我不能用filter方法。
修改后的代码:
const list = computed(() => store.state.menuList)
const noChildren = computed(() => list.value.filter(item => !item.children))
要么在里面return出去也行