zhetengbiji / mp-storage

小程序(兼容 mpvue) Storage 垫片,用于在各个小程序平台(兼容 Web)实现 localStorage、sessionStorage 全部 API
9 stars 8 forks source link

报错? #2

Open qiuyan81 opened 4 years ago

qiuyan81 commented 4 years ago

import Vue from 'vue' import Vuex from 'vuex'

import createPersistedState from "vuex-persistedstate" Vue.use(Vuex) import { localStorage,sessionStorage } from 'mp-storage'//这句引用就报错

/ 错误内容: eportJSException >>>> exception function:createInstanceContext, exception:white screen cause create instanceContext failed,check js stack ->Exception: TypeError: null is not an object (evaluating 'i.length') / import createLogger from 'vuex/dist/logger' // 判断环境 vuex提示生产环境中不使用 const debug = process.env.NODE_ENV !== 'production' const store = new Vuex.Store({ // plugins: debug?[createLogger,createPersistedState({ // storage: window.sessionStorage // })]:[createPersistedState({ // storage: window.sessionStorage // })], plugins: [ createPersistedState({ storage: localStorage }) ],

state: {
    hasLogin: false,
    openId:null,
    companyId:null,
    appId: null,
    last_url: null,
    params:{},

    systemInfo: {},
    loginInfo: {},
},
mutations: {
    login(state, openId) {
        state.hasLogin = true;
        state.openId = openId;
    },
    logout(state) {
        state.hasLogin = false
        state.openId = null
        state.companyId=null
    },
    setOpenId(state,openId){
        state.openId=openId
    },
     setCompanyId(state,companyId){
        state.companyId=companyId
     },
     setAppId(state,appId){
         state.appId=appId
     },
     setLast_url(state,last_url){
         state.last_url=last_url
     },
     setParams(state,params){
         state.params=params
     },
     setSystemInfo(state,systemInfo){
         state.systemInfo=systemInfo
     },
     setLoginInfo(state,loginInfo){
         state.loginInfo=loginInfo
     }
},
getters:{       
},
actions: {
    // lazy loading openid
    getUserOpenId: async function ({
        commit,
        state
    }) {
        return await new Promise((resolve, reject) => {
            if (state.openid) {
                resolve(state.openid)
            } else {
                uni.login({
                    success: (data) => {
                        commit('login')
                        setTimeout(function () { //模拟异步请求服务器获取 openid
                            const openid = '123456789'
                            console.log('uni.request mock openid[' + openid + ']');
                            commit('setOpenid', openid)
                            resolve(openid)
                        }, 1000)
                    },
                    fail: (err) => {
                        console.log('uni.login 接口调用失败,将无法正常使用开放接口等服务', err)
                        reject(err)
                    }
                })
            }
        })
    }
}

})

export default store

zhetengbiji commented 4 years ago

import 应该放在顶部