【发布时间】:2021-06-08 15:28:39
【问题描述】:
我想用 vue3 和 vuex 构建一个应用程序。我在使用 $store 时遇到错误(Uncaught (in promise) TypeError: Cannot read property '$store' of undefined)。但我没有找到任何相关信息。你能帮帮我吗?
import { createApp } from "vue";
import App from "./App.vue";
import router from "./router";
import { store } from "./store";
createApp(App)
.use(store)
.use(router)
.mount("#app");
main.js
<template>
{{ posts }}
<button @click="clickOnButton">Tıkla</button>
</template>
<script>
export default {
name: "HelloWorld",
props: {
msg: String
},
computed: {
posts: () => this.$store.state.post
},
methods: {
clickOnButton: () => {
this.$store.commit("getPost");
}
}
};
</script>
组件
【问题讨论】:
-
这能回答你的问题吗? VueJS: why is "this" undefined?