1,打开 .env.development ?.env.production .env.staging 修改
VUE_APP_BASE_API = '/api'
2,打开utils 目录里的request.js文件
22行
config.headers['Authorization'] = getToken()
49行,if (res.code !== 200)
3,修改登录方法请求,打开文件 src/api/user.js,请根据自己业务修改
export function login(data) {
return request({
url: '/admni/login',
method: 'post',
data
})
}
4修改 modules /user.js
// user login
login({ commit }, userInfo) {
const { username, password } = userInfo
return new Promise((resolve, reject) => {
login({ username: username.trim(), password: password }).then(response => {
console.log(response.data.access_token)
commit('SET_TOKEN', 'Bearer ' + response.data.access_token)
setToken('Bearer ' + response.data.access_token)
resolve()
}).catch(error => {
reject(error)
})
})
},
// get user info
getInfo({ commit, state }) {
return new Promise((resolve, reject) => {
getInfo().then(response => {
const { data } = response
if (!response) {
return reject('Verification failed, please Login again.')
}
const { name, avatar } = data
commit('SET_NAME', name)
commit('SET_AVATAR', avatar)
resolve(data)
}).catch(error => {
reject(error)
})
})
},
?
|