Use the data caching api provided by uni-app uni.setStorageSync('token','res.data.data'); save token
login() {
uni.request({
url:this.apiUrl+"api/index/login",
method:'POST',
// 传参
data:{
telphone:this.telphone,
password:this.password
},
success:(res)=> {
console.log(res.data);
// 登录失败验证
if(res.data.code == 0) {
uni.showToast({
title: res.data.msg,
icon:'none'
});
} else {
console.log(res.data.data);
// 保存 token
uni.setStorageSync('token', res.data.data.token);
}
}
})
}
Get token
uni.getStorageSync('token')