Commit 01205811 authored by yyh's avatar yyh

允许多个toast

parent 54767591
...@@ -6,6 +6,7 @@ import axios from 'axios'; ...@@ -6,6 +6,7 @@ import axios from 'axios';
import router from '../router'; import router from '../router';
import store from '../store/index'; import store from '../store/index';
import { Toast } from 'vant'; import { Toast } from 'vant';
Toast.allowMultiple(true) ;
const pendingAjax: any = []; const pendingAjax: any = [];
const fastClickMsg = '数据请求中,请稍后'; const fastClickMsg = '数据请求中,请稍后';
const CancelToken = axios.CancelToken; const CancelToken = axios.CancelToken;
...@@ -24,8 +25,8 @@ const removePendingAjax = (config: any, c?: any) => { ...@@ -24,8 +25,8 @@ const removePendingAjax = (config: any, c?: any) => {
*/ */
const tip = (msg: string) => { const tip = (msg: string) => {
Toast({ Toast({
message: msg, message: `${msg}`,
duration: 1000, duration: 2000,
forbidClick: true, forbidClick: true,
}); });
}; };
...@@ -75,7 +76,7 @@ const errorHandle = (status: number, other: any) => { ...@@ -75,7 +76,7 @@ const errorHandle = (status: number, other: any) => {
const instance = axios.create({ timeout: 1000 * 12}); const instance = axios.create({ timeout: 1000 * 12});
// 设置post请求头 // 设置post请求头
instance.defaults.headers.post['Content-Type'] = 'application/json'; instance.defaults.headers.post['Content-Type'] = 'application/json';
let loading: any;
/** /**
* 请求拦截器 * 请求拦截器
* 每次请求前,如果存在token则在请求头中携带token * 每次请求前,如果存在token则在请求头中携带token
...@@ -89,7 +90,7 @@ instance.interceptors.request.use( ...@@ -89,7 +90,7 @@ instance.interceptors.request.use(
// token && (config.headers.Authorization = token); // token && (config.headers.Authorization = token);
const url = config.url as string; const url = config.url as string;
if (url.indexOf('list') < 0 ) { if (url.indexOf('list') < 0 ) {
const toast = Toast({ loading = Toast({
type: 'loading', type: 'loading',
duration: 0, duration: 0,
forbidClick: true, forbidClick: true,
...@@ -111,7 +112,7 @@ instance.interceptors.response.use( ...@@ -111,7 +112,7 @@ instance.interceptors.response.use(
(res: any) => { (res: any) => {
removePendingAjax(res.config); removePendingAjax(res.config);
setTimeout(() => { setTimeout(() => {
Toast.clear(); loading.clear();
}, 200); }, 200);
if ( res.status === 200) { if ( res.status === 200) {
if (res.data.code === 200) { if (res.data.code === 200) {
......
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