<router-link to="/login">{{ $store.state.userName }}</router-link>
<router-link to="/login">{{ store.state.userName }}</router-link>
<router-link to="/login">{{ this.store.state.userName }}</router-link>
<router-link to="/login">{{ this.$store.state.userName }}</router-link>
I have never been able to figure out the difference between store
and $store
in vuex, and I don’t know when to add this
in front of it. Please let me know.
—— thanks in advance
$store
is mounted on the Vue instance (i.e. Vue.prototype), and the component is actually a Vue instance. You can usethis
in the component to access the properties on the prototype. The template has the context of the component instance. It can be accessed directly through{{ $store.state.userName }}
, which is equivalent tothis.$store.state.userName
in script.As for
{{ store.state.userName }}
, thedata
in the script must be declaredstore
before it can be accessed.