我的 Nuxt.js 设置遇到一些奇怪的问题。Store 中的某些状态不是持久的,每次我加载另一个视图时,它们都会回到默认值。
页面/test.vue
<template>
<section class="section">
<b-container>
<b-row>
<b-col cols=12>
<b-button @click="setTest" variant="dark">test</b-button> | {{this.$store.state.test}} |
</b-col>
</b-row>
</b-container>
</section>
</template>
<script>
export default {
name: 'test',
methods: {
setTest() {
this.$store.commit("setTest")
},
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
商店/index.js
export const state = () => ({
test: "test"
})
export const mutations = {
setTest: (state) => state.test = 'Hello'
}
Run Code Online (Sandbox Code Playgroud)
测试场景是点击“测试”按钮,调用带有突变提交“setTest”的方法,将状态设置为“Hello”。目前它工作正常,但如果我更改视图或重新加载页面,状态将设置为默认“测试”。
我究竟做错了什么?