url全局地址封装 vue_vue设置全局访问接口API地址操作
methods: {
ajaxLoginApi: function (form) {
var that=this.form; // 放置指針,便于then操作的獲取
console.log("賬號"+that.username+"密碼"+that.pwd);
var localPath = this.GLOBAL.localSrc; // 本地 接口地址 【注釋1】
var serverPath = this.GLOBAL.serverSrc; // 線上 接口地址【注釋2】
axios.post( serverPath + '/login',?? // 【注釋3】
{
// 'userName':'17681135201',
// 'userPwd':'123456',
// 'userType':"2"
'userName': this.form.username,
'userPwd': this.form.pwd,
'userType':"2"
},
{
headers: {
'Content-Type':'application/json',
//'Authorization':'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VySWQiOiI1QUZFRkQ4NTNFNjIwNDIyOEIwNDE3MzdCMDdBNEJCNURDNTBEQjA4OUFCQzBENDM4MDA5RkM4REU4QkMyODkzIiwidXNlck5hbWUiOiIxNzY4MTEzNTIwMSIsInVzZXJBZ2VudCI6Ik1vemlsbGEvNS4wIChXaW5kb3dzIE5UIDEwLjA7IFdpbjY0OyB4NjQpIEFwcGxlV2ViS2l0LzUzNy4zNiAoS0hUTUwsIGxpa2UgR2Vja28pIENocm9tZS82OC4wLjM0NDAuMTA2IFNhZmFyaS81MzcuMzYiLCJleHAiOjE1NTE5MzYzODQsIm5iZiI6MTU1MTkzNDU4NH0.YgRW-Wnlk_Gz64id_jTocH68oj8DuZuI1WyQBmmrt7c'
}
},
)
.then(function (response) {
console.log("response="+response);
console.log("responseheader="+response.headers);
var reslutData = response;
// console.log(reslutData.data.code);
// 登錄賬號和密碼 檢測
if (reslutData.data.code == 2006) { // 用戶名不存在
this.$notify.error({
title: reslutData.data.message,
duration: 2000
});
return false;
}
if (reslutData.data.code != 200) { // 登錄失敗
this.$notify.error({
title: reslutData.data.message,
duration: 2000
});
return false;
} else { // 登錄成功
// 彈框成功提示
this.$notify({
title: reslutData.data.message,
// message: '正在跳轉中···',
type: 'success',
duration: 2000
});
console.log("token=" + reslutData.data.data.token)
// token寫入本地客戶端存儲
localStorage.setItem("token",reslutData.data.data.token);
// token獲取本地客戶端存儲
// var key = localStorage.getItem("token");
// console.log("key=" + key)
// 成功之后執行跳轉? this.$router.replace
this.$router.replace('/search');
}
}.bind(this))
.catch(function (error) {
console.log("請求失敗"+error);
});
},
總結
以上是生活随笔為你收集整理的url全局地址封装 vue_vue设置全局访问接口API地址操作的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: utorrent设置上传速度_utorr
- 下一篇: git 撤销刚才的rebase_git