Vuex 导出踩坑

夏沫花火zzz🌙 (Muska_Ami) Lv4

报错:

1
statuz is not defined

调用:

1
2
3
import statuz from '@/src/script/vuex/statuz'

statuz.commit("loading", true)

非常纸张的一次踩坑,原因竟是const没对
错误示范:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import vuex from 'vuex'

const store = new vuex.Store({ // <- Here
state: ref({
loading: true
}),
getters: {
loading(state) {
return state.loading
}
},
mutations: {
loading(state, status) {
state.loading = status
}
}
})
export default statuz

正确示范:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import vuex from 'vuex'

const statuz = new vuex.Store({ // Here
state: ref({
loading: true
}),
getters: {
loading(state) {
return state.loading
}
},
mutations: {
loading(state, status) {
state.loading = status
}
}
})

export default statuz

应该不会有人跟我这样脑子抽风了罢 (bushi

  • 标题: Vuex 导出踩坑
  • 作者: 夏沫花火zzz🌙 (Muska_Ami)
  • 创建于 : 2023-09-29 06:00:44
  • 更新于 : 2024-10-03 16:39:27
  • 链接: https://blog.1l1.icu/2023/09/28/vuex-dao-chu-cai-keng/
  • 版权声明: 本文章采用 CC BY-SA 4.0 进行许可。
 评论
此页目录
Vuex 导出踩坑