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 31 32 33 34 35
| 新增 src/plugins/axiosInstance.js
import axios from 'axios'
const SendRequest = axios.create({ baseURL: "https://" + import.meta.env.VITE_BASIC_API, timeout: 2000, headers: {'Content-Type': 'application/x-www-form-urlencoded'} });
export default SendRequest
使用: import SendRequest from "@/plugins/axiosInstance";
SendRequest({ method: 'post', url: '/register', data: { email: this.email, password: this.password }, }).then((resp) => { ElNotification({ title: "请求成功", message: "注册成功,等待管理员审批", type: 'success', }) }).catch((err) => { ElNotification({ title: "请求失败", message: err.response.data, type: 'error', }) });
|