引入第三方插件,有個(gè)監(jiān)聽,當(dāng)?shù)诙芜M(jìn)入之后監(jiān)聽到的要更改視圖,但是無果,用vuex最簡(jiǎn)單的解決此問題
1.引入vuex
2.創(chuàng)建store文件,添加index.js
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const state = {
? arr:[],
? mentionedJson:{}
}
const mutations = {
? ? modifyArray(state, obj){
? ? ? ? if(!!obj)
? ? ? ? {
? ? ? ? ? ? state.arr= obj
? ? ? ? }
? ? ? },
}
export default new Vuex.Store({
? state,
? mutations,
})
3.main.js??
import store from './store/index.js'
new Vue({
? ? el: '#app',
? ? router,
? ? store,
? ? components: { App },
? ? template: '<App/>'
})
4.使用
computed:{
? ? historyList(){
? ? ? return this.$store.state.arr;??
? ? },
? },
事件中監(jiān)聽修改
let array = [1,2,3]
_this.$store.commit('modifyArray',array?);