vuex未知突变类型:Nativescript应用

时间:2019-02-06 18:13:30

标签: vue.js nativescript vuex nativescript-vue

我正在编写一个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
    }
}

0 个答案:

没有答案