# 后台登录功能解决方案
# 配置生产环境和开发环境
# 标志
ENV = 'development'
# base api
VUE_APP_BASE_API = '/api'
# 标志
ENV = 'production'
# base api
VUE_APP_BASE_API = '/prod-api'
# 配置接口代理
module.exports = {
devServer: {
proxy: {
'/api': {
target: '后台地址',
changeOrigin: true
}
}
}
}
# 封装 axios 模块
import axios from 'axios'
import {
ElMessage } from 'element-plus'
const service = axios.create({
baseURL: process.env.VUE_APP_BASE_API,
timeout: 5000
})
service.interceptors.request.use(
config => {
config.headers.code = '参数值'
return config
}
)
service.interceptors.response.use(
response => {
const {
success, message, data } = response.data
if (success) {
return data
} else {
ElMessage.error(message