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)
浙公网安备 33010602011771号