Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vue.js 尝试使用Vuex&;测试getters方法;Vue_Vue.js_Getter_Vuex - Fatal编程技术网

Vue.js 尝试使用Vuex&;测试getters方法;Vue

Vue.js 尝试使用Vuex&;测试getters方法;Vue,vue.js,getter,vuex,Vue.js,Getter,Vuex,我是Vuex新手,正在尝试使用getter从状态返回数据属性的简单测试。我试图在页面上显示返回的数据 组件.VUE <template> <div class="section" > <div class="section-content"> <p>{{test.title}}</p> </di

我是Vuex新手,正在尝试使用getter从状态返回数据属性的简单测试。我试图在页面上显示返回的数据

组件.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>
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
    })

我得到的错误是testis-Property或方法“test”没有在实例上定义,而是在呈现期间引用。是否还有另一个步骤可以将数据保存到我遗漏的组件中?

将computed属性
getTest
更改为just
test
,我想这很简单!感谢您阅读我的文章,了解如何在测试中模拟vuex-
    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
    })