我是Vuex的新手,我正在尝试使用getter从状态返回数据属性的简单测试。我试图在页面上显示返回的数据。
COMPONENT.VUE
<template>
<div class="section" >
<div class="section-content">
<p>{{test.title}}</p>
</div>
</div>
</template>
<script>
export default {
name: 'startNewSearch',
computed: {
getTest() { return this.$store.getters.getTest }
}
}
</script>
GETTERS.JS
export default {
getTest(state) {
return state.test
}
}
STORE.JS
import Vue from 'vue'
import Vuex from 'vuex'
import actions from './actions'
import mutations from './mutations'
import getters from './getters'
Vue.use(Vuex);
export const store = new Vuex.Store({
state: {
newSearch: {},
test: {
title: 'Test',
msg: 'This is a test message'
}
},
getters,
mutations,
actions
})
我得到的错误是测试是 - 属性或方法&#34;测试&#34;未在实例上定义,但在呈现期间引用。还有另一步将数据保存到我错过的组件中吗?