Vuex: _this.$store is undefined

后端 未结 3 1339
盖世英雄少女心
盖世英雄少女心 2020-12-07 02:47

After adding Vuex to my project I am unable to access this.$store in any components. The error message is

TypeError: _this.$store is undefined

相关标签:
3条回答
  • 2020-12-07 03:17

    SOLVED:

    Using fat arrow on created is not correct, should be created: function() {...}

    0 讨论(0)
  • 2020-12-07 03:17

    When arrow functions are used "this" will not be the Vue instance as you’d expect since arrow functions are bound to the parent context. Instead,

        created() { //function body. "this" will be the Vue instance},
        mounted() {//function body. "this" will be the Vue instance},
        methods: { someFunc() {}, async someAsyncFunc {} }
    
    0 讨论(0)
  • I also encountered this problem after moving the store from app.js to /store/index.js

    I had to change state.store.myValue to store.myValue in the commits

    0 讨论(0)
提交回复
热议问题