19302com
19302com
  • 发布:2022-04-29 10:33
  • 更新:2022-04-29 11:04
  • 阅读:1020

uniapp使用vue3后反向代理问题

分类:uni-app

manifest.json设置VUE版本3

根目录新建vite.config.js文件

import { defineConfig } from 'vite'  

export default defineConfig({  
    server: {  
        port : 3001,  
        proxy: {  
            '/api': {  
                target: 'http://jsonplaceholder.typicode.com',  
                changeOrigin: true,  
                rewrite: (path) => path.replace(/^\/api/, '')  
            },  
        }  
    }  
})

运行时报错

10:26:32.866 正在编译中...  
10:26:33.062 Port 3000 is in use, trying another one...  
10:26:33.064   vite v2.9.5 dev server running at:  
10:26:33.065   > Local: http://localhost:3001/  
10:26:33.067   > Network: use `--host` to expose  
10:26:33.072   ready in 811ms.  
10:26:33.117 The following dependencies are imported but could not be resolved:  
10:26:33.119   vue (imported by E:/flx-code/uni-app-sxrd/main.js)  
10:26:33.121   vuex (imported by E:/flx-code/uni-app-sxrd/store/index.js)  
10:26:33.125 Are they installed?

大佬们,我是不是用错了,怎么解决啊

尝试:直接npm i安装 vue和vuex这个报错没了,但是App.vue就不能用了...

2022-04-29 10:33 负责人:无 分享
已邀请:
DCloud_UNI_FXY

DCloud_UNI_FXY

自定义 vite.config 时,必须注册 uni 的插件

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

/**  
 * @type {import('vite').UserConfig}  
 */  
export default defineConfig({  
  plugins: [uni()],  
});  
  • zhaoyu2020

    原来vue2 ,manifest中设置反代理是正常获取api的 , 改成vue3 就报404了?需要特殊设置吗?

    2023-02-23 11:01

要回复问题请先登录注册