Vue-admin修改登录接口,怎么解决报data错误问题(帮帮忙)
粉丝福利 : 关注VUE中文社区公众号,回复视频领取粉丝福利
我看了官方文档,没看懂
有没有懂得大佬,帮帮小弟
研究两天了,。,,,
// 引入sign方法
import signs from '@/utils/util.js'
const cookdata=JSON.parse(Cookies.get('cookdata'));
const state = {
token:getToken(),
admin_id:cookdata.admin_id,
login_time:cookdata.login_time,
username:cookdata.username,
}
const mutations = {
SET_ADMINID: (state, admin_id) => {
state.admin_id = admin_id
},
SET_USERNAME: (state, username) => {
state.username = username
},
SET_LOGINTIME: (state, login_time) => {
state.login_time = login_time
},
SET_TOKEN: (state, token) => {
state.token = token
},
}
const actions = {
// user login
login({ commit }, userInfo) {
const {username,pwd,time}=userInfo
var sign=signs.signFun(userInfo);
return new Promise((resolve, reject) => {
login({username:username.trim(),pwd:pwd,time:time},sign).then(response => {
const data =response.data
Cookies.set('cookdata',response.data)
commit('SET_TOKEN', data.token)
setToken(data.token)
resolve()
}).catch(error => {
reject(error)
})
})
},
// get user info
getInfo({ commit, state }) {
const admin_ids= state.admin_id
const tokens=state.token
return new Promise((resolve, reject) => {
getInfo({admin_id:admin_ids,token:tokens}).then(response => {
const dataInfor = JSON.parse(JSON.stringify(state));
var sss={
roles: ['editor'],
introduction: 'I am an editor',
avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
name: 'Normal Editor'
}
console.log(sss,dataInfor)
// debugger
if (!dataInfor) {
reject('验证失败,请重新登录!')
}
const { admin_id, username, login_time, token } = dataInfor
commit('SET_TOKEN', token);
commit('SET_ADMINID', admin_id);
commit('SET_USERNAME', username)
commit('SET_LOGINTIME', login_time)
resolve(dataInfor)
console.log(dataInfor)
}).catch(error => {
reject(error)
})
})
},