代码拉取完成,页面将自动刷新
实现登录的控制器为Web/Controllers/DefaultController
var token //登录令牌,请求授权操作方法需携带此令牌
axios.post("http://127.0.0.1:5000/api/login",{username:"admin",password:"123456",type:"user"}).then(r=>{
//console.log(r.data)
if(r.status&&r.data.status){
console.log(r.data.data)//登录用户信息
token=r.data.data.token//获取登录令牌
}
})
var token //登录令牌,请求授权操作方法需携带此令牌
axios.post("http://127.0.0.1:5000/api/wxMplogin",{code:"小程序code",username:"xioayouyu",avatar:"头像"},
{headers: { 'content-type': 'application/x-www-form-urlencoded' }}).then(r=>{
//console.log(r.data)
if(r.status&&r.data.status){
console.log(r.data.data)//登录用户信息
token=r.data.data.token//获取登录令牌
}
})
var token //登录令牌,请求授权操作方法需携带此令牌
axios.post("http://127.0.0.1:5000/api/wxApplogin",{access_token:"微信access_token",openid:"openid"},
{headers: { 'content-type': 'application/x-www-form-urlencoded' }}).then(r=>{
//console.log(r.data)
if(r.status&&r.data.status){
console.log(r.data.data)//登录用户信息
token=r.data.data.token//获取登录令牌
}
})
请求需要授权才能访问的操作方法(加[Authorize]或[Authority]注解的方法)需要在header携带token,如访问获取用户信息的操作方法GetUserinfo
axios.get("http://127.0.0.1:5000/api/getuserinfo",
{headers: { 'Authorization': 'Bearer '+token }}).then(r=>{ //token为登录获取的token值
//console.log(r.data)
if(r.status&&r.data.status){
console.log(r.data.data)//获取用户信息
}
})
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。