vue中的浏览量_vue中访问数据接口的配置

博客介绍了Vue开发中业务API接口和前端UI浏览地址,因同源策略需配置代理,给出开发环境下config/index.js的代理配置。还说明了在main.js中配置axios请求基础地址,配置后发请求无需添加具体域名。同时提出配置中发现的问题,如baseURL必须配置,config/index.js地址不配置也能访问数据。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

业务API接口地址: http://localhost:3816/api/

前端UI浏览地址:http://127.0.0.1:8080/#/home

由于同源策略的问题: 需要配置代理:

在开发环境下配置如下:config/index.js

assetsSubDirectory: ‘static‘,

assetsPublicPath: ‘/‘,

proxyTable: {

‘/api‘: { //将www.exaple.com印射为/apis

target: ‘http://localhost:3816/api/‘, // 接口域名

changeOrigin: true, //是否跨域

pathRewrite: {

‘^/api‘: ‘/‘,

}

}

},

// Various Dev Server settings

host: ‘localhost‘, // can be overwritten by process.env.HOST

port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined

autoOpenBrowser: true,

errorOverlay: true,

notifyOnErrors: true,

poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-

主要内容为

proxyTable: {

‘/api‘: { //将www.exaple.com印射为/apis

target: ‘http://localhost:3816/api/‘, // 接口域名

changeOrigin: true, //是否跨域

pathRewrite: {

‘^/api‘: ‘/‘,

}

}

},

在main.js 配置axios 请求的基础地址时:

如下:

import axios from ‘axios‘import Vuexfrom ‘vuex‘import IViewfrom ‘iview‘import‘iview/dist/styles/iview.css‘;

Vue.use(IView);

Vue.use(Vuex);

Vue.prototype.axios=axios;

axios.defaults.timeout= 500000;

axios.defaults.headers.post[‘Content-Type‘] = ‘application/json;charset=UTF-8‘;

axios.defaults.baseURL= "http://localhost:3816/api/";

数据请求的基础接口地址为      http://localhost:3816/api/    这样配置后就可以在发请求的时候,不需要添加具体的域名地址了,就可以访问数据

如:

this.axios.get("Values")

.then(Response => {

console.log(Response);

});

这配置的过程中发现如下问题:

1.baseURL 必须配置。

2.config/index.js  中的地址不配置 也可以访问到数据 原因未知,欢迎告知

两者具体由什么联系呢????

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值