import { defineNuxtPlugin } from '#app' import axios from 'axios' import { getToken } from '@/store/useCookieStore' export default defineNuxtPlugin(nuxtApp => { const service = axios.create({ // baseURL: 'http://183.131.25.186:9501' //测试服务器地址 baseURL: 'http://admindev.bjzxtw.org.cn:9501' //测试服务器地址 // baseURL: 'http://192.168.1.234:9501' //pre服务器地址 // baseURL: 'http://192.168.1.113:9501' //冯蕊的服务器地址 // baseURL: 'http://192.168.1.201:9501' //刘佳伟的服务器地址 }); // 请求拦截器 service.interceptors.request.use(config => { // console.log("请求拦截器",config); // 从cookie中获取数据 const token = getToken() // const token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJwaHBlcjY2Ni9qd3QiLCJ1aWQiOjMyLCJ1c2VyX25hbWUiOiIxNTIxMDIxMTIwMCIsIm1vYmlsZSI6IjE1ODAxMjQ1NzU1IiwiZW1haWwiOiI1QHFxLmNvbSIsImxldmVsX2lkIjoxLCJ0eXBlX2lkIjoxMDAwMCwiand0X3NjZW5lIjoiZGVmYXVsdCIsImp0aSI6ImRlZmF1bHRfNjdiMjljMWU3YjJjMTYuNjU2OTU0NjgiLCJpYXQiOjE3Mzk3NTg2MjIsIm5iZiI6MTczOTc1ODYyMiwiZXhwIjoxNzM5ODQ1MDIyfQ.TS6WvlYA1q1g-88MEZgzu5iOWfQ1o64FoAyX2avMoZM" if (token) { config.headers.token = token; } return config; }, error => { console.log(error) return Promise.reject(error); }); // 响应拦截器 service.interceptors.response.use(response => { if (response.status >= 200 && response.status <= 210) { return response.data; } else if (response.status == 404) { console.error(response.data.errmsg); } else { } }, error => { // console.log(1); console.log('err' + error); }) return { provide: { axios: service }, } });