uv_UI
uv_UI
  • 发布:2021-09-16 18:40
  • 更新:2021-11-07 18:28
  • 阅读:2374

关于uniapp H5 + VUE3 请求无返回值,好像与vite的配置有关系

分类:uni-app
  1. 为了解决请求跨域问题,于是配置了代理解决跨域
    "devServer": {
    "port": 8080, //端口号
    "disableHostCheck": true,
    "proxy": {
    "/api": {
    "target": "https://api.book118.com", //目标接口域名
    "changeOrigin": true, //是否跨域
    "secure": true, // 设置支持https协议的代理
    "pathRewrite": {
    "^/api": ""
    }
    }
    }
    }
  2. 使用vue2打包就是正常的,但是使用VUE3打包就提示需要设置server.fs.allow什么的,又不知道具体怎么设置
    18:34:35.998 Unrestricted file system access to "/api/applet/index/getRecommendDocs"
    18:34:35.998 For security concerns, accessing files outside of serving allow list will be restricted by default in the future version of Vite. Refer to https://vitejs.dev/config/#server-fs-allow for more details.
2021-09-16 18:40 负责人:无 分享
已邀请:
v***@vip.qq.com

v***@vip.qq.com

在 vite.config.js 配置:

import { defineConfig } from 'vite'  
import uni from '@dcloudio/vite-plugin-uni'  

export default defineConfig({  
plugins: [  
uni(),  
],  
server: {  
port: 3344,  
proxy: {  
'/api': {  
target: 'http://xxxxxx', // 自己的云服务  
changeOrigin: true,  
rewrite: path => path.replace(/^\/api/, ''),  
},  
},  
},  
})
  • 快乐的小pig

    好人一生平安

    2021-11-11 16:33

  • 4***@qq.com

    好像运行到浏览器可以,运行到手机不行?

    2023-01-28 10:47

uv_UI

uv_UI (作者) - 我与uniapp有着不解的缘分~

麻烦知道的给个回复嘛

uv_UI

uv_UI (作者) - 我与uniapp有着不解的缘分~

官方的给个回复呗

fxy060608

fxy060608

vue3的话,先使用vite.config.js配置proxy

https://cn.vitejs.dev/config/#server-proxy

  • 4***@qq.com

    好像运行到浏览器可以,运行到手机不行?

    2023-01-28 10:47

该问题目前已经被锁定, 无法添加新回复