Zak*_*dov 5 javascript vue.js vuex
在一个简单的应用程序中,我创建了一组与组件创建挂钩相关联的简单突变和操作。在浏览器中,按 F5 后,当在 Vuex 选项卡上打开 vue-devtools 时,我在应用程序开始时收到错误消息,尽管这不应该发生。
主要问题:为什么状态为“空”以及如何更改它?
商店.js
export default new Vuex.Store({
state: {
a: undefined,
b: undefined
},
mutations: {
SET_A (state, a) {
console.info(a)
state.a = a // ? store.js?c0d6:14
},
SET_B (state, b) {
state.b = b
}
},
actions: {
setA ({ commit }, a) {
console.info(a)
commit('SET_A', a)
},
setB ({ commit }, b) {
commit('SET_B', b)
}
}
})
Run Code Online (Sandbox Code Playgroud)
主页.vue
<script>
// @ is an alias to /src
import HelloWorld from '@/components/HelloWorld.vue'
export default {
name: 'home',
components: {
HelloWorld
},
created: function () {
this.$store.dispatch('setA', 'A')
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
关于.vue
<script>
export default {
name: 'home',
components: {
},
created: function () {
this.$store.dispatch('setB', 'B')
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
控制台登录组件选项卡
log.js?1afd:24 [HMR] Waiting for update signal from WDS...
store.js?c0d6:22 A
store.js?c0d6:13 A
backend.js:1585 vue-devtools Detected Vue v2.6.10
Run Code Online (Sandbox Code Playgroud)
Vuex 选项卡上的控制台登录
log.js?1afd:24 [HMR] Waiting for update signal from WDS...
store.js?c0d6:22 A
store.js?c0d6:13 A
backend.js:1585 vue-devtools Detected Vue v2.6.10
store.js?c0d6:13 null
backend.js:14674 Uncaught TypeError: Cannot set property 'a' of null
at Store.SET_A (store.js?c0d6:14)
at wrappedMutationHandler (vuex.esm.js?2ba1:725)
at backend.js:14664
at Array.forEach (<anonymous>)
at VuexBackend.replayMutations (backend.js:14664)
at VuexBackend.onInspectState (backend.js:14355)
at Bridge.emit (backend.js:5472)
at Bridge._emit (backend.js:5172)
at backend.js:5097
at Array.forEach (<anonymous>)
SET_A @ store.js?c0d6:14
wrappedMutationHandler @ vuex.esm.js?2ba1:725
(anonymous) @ backend.js:14664
replayMutations @ backend.js:14664
onInspectState @ backend.js:14355
emit @ backend.js:5472
_emit @ backend.js:5172
(anonymous) @ backend.js:5097
(anonymous) @ backend.js:5097
listener @ backend.js:2568
postMessage (async)
o @ proxy.js:1
store.js?c0d6:13 null
backend.js:14674 Uncaught TypeError: Cannot set property 'a' of null
at Store.SET_A (store.js?c0d6:14)
at wrappedMutationHandler (vuex.esm.js?2ba1:725)
at backend.js:14664
at Array.forEach (<anonymous>)
at VuexBackend.replayMutations (backend.js:14664)
at VuexBackend.onInspectState (backend.js:14355)
at Bridge.emit (backend.js:5472)
at Bridge._emit (backend.js:5172)
at backend.js:5097
at Array.forEach (<anonymous>)
SET_A @ store.js?c0d6:14
wrappedMutationHandler @ vuex.esm.js?2ba1:725
(anonymous) @ backend.js:14664
replayMutations @ backend.js:14664
onInspectState @ backend.js:14355
emit @ backend.js:5472
_emit @ backend.js:5172
(anonymous) @ backend.js:5097
(anonymous) @ backend.js:5097
listener @ backend.js:2568
postMessage (async)
o @ proxy.js:1
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1813 次 |
| 最近记录: |