Vue CLI 3.0中如何配置proxy代理实现长尾词请求转发?
- 内容介绍
- 文章标签
- 相关推荐
本文共计158个文字,预计阅读时间需要1分钟。
解决方法:在Vue项目的根目录下添加vue.config.js文件,内容如下:
javascriptmodule.exports={ lintOnSave: true, devServer: { proxy: { '/api': { target: 'https://jsonplaceholder.typicode.com/api', changeOrigin: true, pathRewrite: { '^/api': '' } } } }}
解决方法:
在vue项目的根目录下添加 vue.config.js文件,文件中需要按照下面写法来写
module.exports = { lintOnSave: true, devServer: { proxy: { // proxy all requests starting with /api to jsonplaceholder '/api': { target: 'localhost:8080', //代理接口 changeOrigin: true, pathRewrite: { '^/api': '/mock' //代理的路径 } } } } }
然后你就可以在代码中使用 /api 来代替localhost:8080/mock啦
以上这篇vue 实现cli3.0中使用proxy进行代理转发就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持易盾网络。
本文共计158个文字,预计阅读时间需要1分钟。
解决方法:在Vue项目的根目录下添加vue.config.js文件,内容如下:
javascriptmodule.exports={ lintOnSave: true, devServer: { proxy: { '/api': { target: 'https://jsonplaceholder.typicode.com/api', changeOrigin: true, pathRewrite: { '^/api': '' } } } }}
解决方法:
在vue项目的根目录下添加 vue.config.js文件,文件中需要按照下面写法来写
module.exports = { lintOnSave: true, devServer: { proxy: { // proxy all requests starting with /api to jsonplaceholder '/api': { target: 'localhost:8080', //代理接口 changeOrigin: true, pathRewrite: { '^/api': '/mock' //代理的路径 } } } } }
然后你就可以在代码中使用 /api 来代替localhost:8080/mock啦
以上这篇vue 实现cli3.0中使用proxy进行代理转发就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持易盾网络。

