When accessing data in Vuex, use the pointing problem of this here in this.$store.state.city in the component?

When accessing data in

Vuex, it is a bit confusing to use the this of this.$store.state.city in a single-file component. If the this points to the current component, there is no store option in the current component. If this points to the root component app in main.js, there is no problem with data access, but this this obviously refers to the current single-file component. I also hope that the boss will give me some advice to help my younger brother solve his doubts. Thank you

May.26,2021

clipboard.png

ide/state.html" rel=" nofollow noreferrer "> https://vuex.vuejs.org/zh/gui.


injects values into the root component like $route and is accessible in all subcomponents.


it can be understood that main.js is an ancestor. If you give something to your ancestors, something from your ancestors will be passed on to future generations, so future generations can use it through this. I don't know if I can understand this.

Menu