最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

laravel - Vuetify+Vuex Store - "$store" was accessed during render but is not defined on instance - Stack Over

programmeradmin3浏览0评论

i´m trying to create an app with laravel 12 and vuetify. I´m following the steps of: .html#getting-vuex-state-into-vue-components but i cant make working.

The browser is empty and the console show (App.vue:10): Uncaught TypeError: Cannot read properties of undefined (reading 'state')

store.js:

import { createApp } from 'vue'
import { createStore } from 'vuex'
import App from '../web/App.vue';

const store = createStore({
    state () {
        return {
            count: 0
        }
    },
    mutations: {
        increment (state) {
            state.count++
        }
    }
})

const app = createApp(App)
app.use(store)

app.vue

<template>
  <div>Counter: {{ count }}</div>
  <v-btn @click="increment()">Increment</v-btn>
</template>

<script>
  export default {
    data () {
      return {
        count: this.$store.state.count
      }
    },

    created() {
    },

    mounted() { 
    },

    computed: {
    },

    methods: {
      increment() {
        this.$storemit('increment')
        console.log(this.$store.state.count)
      }
    }
  }
</script>

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论