vue vuex全局變量


1.使用命令 :npm install vuex --save

2.src下新建個文件store,在store下再建個index.js:

import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

const store = new Vuex.Store({
  state:{
    count:1
  }
})
export default store
 
3.main.js中引入store
import store from './store'
new Vue({
  el: '#app',
  router,
   store,
  components: { App },
  template: '<App/>'
})
4.在指定頁面引入:
{{this.$store.state.count}}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM