rk
5 天以前 214cda58c3786972c958da5c6d54a135490a3c11
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const install = (Vue, vm) => {
    // 请求拦截器
    uni.$u.http.interceptors.request.use((config) => {
        // const Headtoken = vm.$store.state.token
        // if (Headtoken) {
            config.header['token'] = 'eyJhbGciOiJIUzUxMiJ9.eyJpZCI6IjE4MDU1MTU5NDUzIiwiZXhwIjoxNzcwMTg3MDgxfQ.xoNzXq98cZQEAlCO3UeJU6zn5obIdoCWxWLRJumlj4AAzVeBNQosrVfxZMBfYOAZKB7qBcM_4JiWlDCEyL8hrg';
        // }
        return config
    }, config => {
        return Promise.reject(config)
    })
    
    // 响应拦截器
    uni.$u.http.interceptors.response.use((response) => {
        // 接口业务报错
        if (response.data.code !== 200) {
            uni.showToast({
                title: response.data.message || response.data.msg,
                icon: "none",
                duration: 2000
            });
            return Promise.reject(response)
        }
        return response.data;
    }, (response) => {
        return Promise.reject(response)
    })
}
 
export default { install }