可以正常访问后端api
This commit is contained in:
@@ -1,11 +1,11 @@
|
|||||||
// API配置文件
|
// API配置文件
|
||||||
const API_CONFIG = {
|
const API_CONFIG = {
|
||||||
// 后端服务基础URL
|
// 后端服务基础URL
|
||||||
BASE_URL: 'http://localhost:8086',
|
BASE_URL: '',
|
||||||
|
|
||||||
// API端点
|
// API端点
|
||||||
ENDPOINTS: {
|
ENDPOINTS: {
|
||||||
DEVICES: '/api/v1/devices'
|
DEVICES: '/v1/devices'
|
||||||
},
|
},
|
||||||
|
|
||||||
// 请求超时时间(毫秒)
|
// 请求超时时间(毫秒)
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import API_CONFIG from '../config/api.js';
|
import API_CONFIG from '../config/api.js';
|
||||||
|
|
||||||
// 创建axios实例
|
// 创建axios实例,自动将请求发送到 BASE_URL + 相对路径
|
||||||
|
// 例如:http.get('/api/pigs') 会请求 BASE_URL + '/api/pigs'
|
||||||
const http = axios.create({
|
const http = axios.create({
|
||||||
baseURL: API_CONFIG.BASE_URL,
|
baseURL: API_CONFIG.BASE_URL,
|
||||||
timeout: API_CONFIG.TIMEOUT,
|
timeout: API_CONFIG.TIMEOUT,
|
||||||
|
|||||||
@@ -46,7 +46,14 @@ module.exports = (env, argv) => {
|
|||||||
hot: true,
|
hot: true,
|
||||||
open: true,
|
open: true,
|
||||||
historyApiFallback: true,
|
historyApiFallback: true,
|
||||||
port: 8080
|
port: 8080,
|
||||||
|
proxy: {
|
||||||
|
'/api': {
|
||||||
|
target: 'http://localhost:8086',
|
||||||
|
changeOrigin: true,
|
||||||
|
secure: false
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
|
|||||||
Reference in New Issue
Block a user