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