vue系列:在js文件中使用vue实例和store实例
// libs/utils.jsimport store from '../store/index'import Vue from '../main.js'Vue.$TaLog({event_id: 'cb',event_comment: '去登陆'})store.commit('TOKEN', {name: 'isRepresent',value: isRepr...
·
// libs/utils.js
import store from '../store/index'
import Vue from '../main.js'
Vue.$TaLog({
event_id: 'cb',
event_comment: '去登陆'
})
store.commit('TOKEN', {
name: 'isRepresent',
value: isRepresent
})
// store/index.js
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store = new Vuex.Store({
state: {
token: '',
// 是代表吗
isRepresent: false
},
mutations: {
TOKEN (state, data) {
state[data.name] = data.value
}
}
})
export default store
// main.js
import Vue from 'vue'
import router from './router'
import store from './store'
/* eslint-disable no-new */
var vue = new Vue({
el: '#app',
router,
store,
components: { App },
template: '<App/>'
})
export default vue
更多推荐
已为社区贡献18条内容
所有评论(0)