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)


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM