vuex引入的两种方法,store和$store区别


引入:import store from '../../../store/index.js'
访问:console.log(store.state.name)
如果每个页面都引入store文件非常麻烦,于是
->将store挂在到实例中,

 

 访问:console.log(this.$store.state.name)

通常项目应用中,更习惯用store挂载到实例中的方式


注:当在template中访问时已拥有组件实例的上下文,可不用this直接{$store.state.name}访问

引申:router挂载到实例中,同this.$store,访问用console.log(this.$router)

posted @ 2020-12-01 14:32  开往秋天  阅读(5726)  评论(0)    收藏  举报