在main.js里已經import store from './vuex'了。說明已經創建了狀態管理器
然后
new Vue({
//eslint-disable-line
el: '#app',
router,
store,
render: h => h(App),
});
也使用了vuex來管理狀態
並且把App.vue界面掛載到#app里。
App.vue創建完成后執行:
$store.state.gis獲取狀態時拿不到值
Vuex一共有5個module:
user、gis、auth。。。
這些全局變量的初始值都是空的。。
this.$store.state.gis.mainMap.invalidateSize();
那么問題就是為什么一直是空的。。
在地圖Mounted(加載)之后便會執行:
this.$store.state.gis.mainMap = this.mainMap;
不是嗎?為什么一直為空呢?
methods:
initBaseMap() {
this.mainMap = L.map(document.getElementById('mainMap'), {
center: [this.lat, this.lng],
zoom: this.zoom,
layers: [this.normal],
zoomControl: false,
attributionControl: false,
doubleClickZoom: true,
editable: true,
});
}
難道沒有執行?
錯誤2:data():serverUrl: this.$store.state.user.config.serverUrl,
在src/vuex/user/index.js底下可以看到
config對象的鍵值對serverUrl:對應為空
