Commit f9adf94c authored by 13841799530's avatar 13841799530

token接口联调

解润东
20211021
parent 79930953
......@@ -7,8 +7,9 @@
* 版权所有,侵权必究!
*/
import axios from 'axios'
import { Toast } from 'vant'
import router from '../router'
import { Notify } from 'vant';
import { getToken } from '@/utils/auth' // get token from cookie
const service = axios.create({
baseURL: '/hse/app-api', //前缀路径
......@@ -21,7 +22,7 @@ const service = axios.create({
//拦截接口请求
service.interceptors.request.use(config => {
if (getToken()) {
config.headers['X-Token'] = getToken()
config.headers['token'] = getToken()
}
return config
},error => {
......@@ -34,27 +35,15 @@ service.interceptors.response.use(response => {
if(code == 200) {//请求响应码200 代表已经请求到接口
if(res.code === 0) {//接口响应码0 代表接口代码运行正常
return res
}else{
this.$notify({
message:'失败',
background:'red',
duration: 1000
})
}else if(res.code === 301){
Notify({ type: 'danger', message: res.msg});
}
}else{
this.$notify({
message:'失败',
background:'red',
duration: 1000
})
Notify({ type: 'danger', message: '失败' });
Promise.reject(new Error('Error'))
}
},err=>{
this.$notify({
message:'失败',
background:'red',
duration: 1000
})
Notify({ type: 'danger', message: '失败' });
return Promise.reject(err)
})
......
......@@ -65,29 +65,17 @@ export default {
},
methods: {
onSubmit(values) {
if(values.username=='admin'&&values.password=='123456'){
getFun('check/token',{a:122}).then((Response)=>{
if(Response.code==0){
this.$notify({
message:'登录成功',
background:'green',
duration: 1000
})
setToken(Response.data)
this.$router.push('/message-center')
}
})
// localStorage.setItem('admin_token','2dsfewr')
// this.$router.push('/MessageCenter')
// location.reload();
}else{
this.$notify({
message:'账号或密码不正确',
background:'red',
duration: 1000
})
}
getFun('check/token',values).then((Response)=>{
if(Response.code==0){
this.$notify({
message:'登录成功',
background:'green',
duration: 1000
})
setToken(Response.data)
this.$router.push('/message-center')
}
})
}
}
};
......
......@@ -38,6 +38,7 @@
<script>
import LHeader from '@/components/header.vue'
import { getFun,postFun } from '@/service/table'
export default {
name: 'checked',
components: {
......@@ -50,9 +51,15 @@ export default {
}
},
mounted() {
this.list()
},
methods: {
list(){
getFun('check/carry/user/list').then((Response)=>{
console.log(Response)
})
},
onSearch(){
this.$toast('提示内容')
},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment