Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

报错? #2

Open
qiuyan81 opened this issue Apr 6, 2020 · 1 comment
Open

报错? #2

qiuyan81 opened this issue Apr 6, 2020 · 1 comment

Comments

@qiuyan81
Copy link

qiuyan81 commented Apr 6, 2020

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
Copy link
Owner

import 应该放在顶部

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants