我正在编写一个 vue.js Nativescript 应用程序。我想让 Vuex 管理移动设备的连接状态
我已经设置了对连接状态的监控并在每次更改时触发的代码,我想在发生这种情况时设置 vuex 状态
当我在模拟器上运行代码时,它会正确检测到状态更改,但会出现此错误
[vuex] unknown mutation type: updateConnectionStatus
我假设代码没有从正确的位置执行,但它不会抱怨找到商店。
这是我的 app.js
import Vue from "nativescript-vue";
import axios from 'axios'
import VueAxios from 'vue-axios'
import router from "./router"
import store from './store/store';
import * as connectivity from "tns-core-modules/connectivity";
const httpModule = require("http");
Vue.prototype.$router = router
Vue.use(VueAxios, axios)
connectivity.startMonitoring((newConnectionType) => {
console.log('monitoring')
switch (newConnectionType) {
case connectivity.connectionType.none:
store.commit('updateConnectionStatus', 'false')
console.log("No network connection available!");
break;
case connectivity.connectionType.wifi:
store.commit('updateConnectionStatus', 'true')
console.log("You are now on wifi!");
break;
case connectivity.connectionType.mobile:
store.commit('updateConnectionStatus', 'true')
console.log("You are now on a mobile data network!");
break;
}
});
new Vue({
render: h => h('frame', [h(router['login'])]),
store,
}).$start()
我的变异器看起来像
const mutations = {
updateConnectionStatus(state,{ status }) {
// mutate state
state.connectionStatus = status
}
}