actionList.includes is not a function?
store.js方法:
actions: {
    async getBtnPermission({ commit }) {
      const res = await getBtnCode();
      const arr = res.split(',');
      console.log('按钮权限列表', arr);
      commit('updateBtnPerm', arr);
    },
  },main.js内使用:
// 按钮权限指令
Vue.directive('has', {
  inserted: (el, binding) => {
    let actionList = store.dispatch('getBtnPermission');
    console.log('actionList', actionList);
    let values = binding.value;
    let hasPermission = actionList.includes(values);
    if (!hasPermission) {
      el.style = 'display:none';
      setTimeout(() => {
        el.parentNode.removeChild(el);
      }, 0);
    }
  },
});为什么会报actionList.includes is not a function?
回复
1个回答

test
2024-07-14
await 呢? async 的返回值是个 promise。
我看你也打印了 actionList。
昂。actions 的返回是什么呢?commit 是指触发 mutation
所以你应该 await 一下,然后从 store 中读取一下 actionList
回复

适合作为回答的
- 经过验证的有效解决办法
- 自己的经验指引,对解决问题有帮助
- 遵循 Markdown 语法排版,代码语义正确
不该作为回答的
- 询问内容细节或回复楼层
- 与题目无关的内容
- “赞”“顶”“同问”“看手册”“解决了没”等毫无意义的内容
