我无法开箱即用Vuex与Nuxt一起工作。我确实尝试按照本指南进行操作,但出现以下错误
我得到的错误:
TypeError
Cannot read property 'state' of undefined
复制步骤:
npx create-nuxt-app
\\Options selected
? Project name **VueNuxtApp**
? Project description **My epic Nuxt.js project**
? Use a custom server framework **none**
? Choose features to install (Press <space> to select, <a> to toggle all, <i> to invert selection)
? Use a custom UI framework **none**
? Use a custom test framework **none**
? Choose rendering mode **Universal**
? Author name
? Choose a package manager **npm**
npm run dev
将pages/index.vue
替换为以下内容:
<template>
<div>
<h3>The website says</h3>
<p>{{ greeting }}</p>
</div>
</template>
<script>
import { mapState } from 'vuex'
export default {
computed: mapState([
'greeting'
]),
}
</script>
为store/index.js
添加了以下内容:
export const state = () => ({
greeting: 'Hello, World'
})
答案 0 :(得分:0)
我知道了。需要重新启动以反映更改。不过,我在官方指南中没有提到这一点。