关于uniapp+vue3+uview-plus的公共包
npm install lby-commonjs
const __DEV__ = false
export const api_url = __DEV__ ? 'https://test.me56.cn' : 'https://m.me56.cn'
export default {
api_url,
isDev: __DEV__
}
`
5. 再main.js中引入
`js
import global from "lby-common/utils/global";
import {
setEnv
} from 'lby-common/config'
uni.gb = global
import env from './env'
setEnv(env)
`
6. 在vite.config.js中配置代理
`js
import env from "./env";
`
`js
{
server: {
cors: true, // 默认启用并允许任何源
open: false, // vite项目启动时自动打开浏览器
host: '0.0.0.0', //设置为0.0.0.0则所有的地址均能访问
port: env.isDev ? 5555 : 5371,
proxy: {
'/api': {
target: env.api_url, // 目标服务
changeOrigin: true,
secure: false,
rewrite: path => path.replace(/^\/api/, ''),
},
}
}
}
`
7. 在pages文件夹下创建并配置login.vue页面
`vue
`
`json
{
"path": "pages/login",
"style": {
"navigationBarTitleText": "登录"
}
},
`
8. 在App.vue 引入公共样式
`style
@import "lby-common/style/index.css";
``