uniapp引入uview-plus3.0
1.新建项目,Vue版本选择3
2.找到uview-plus3.0插件,导入新建项目,插件地址:https://ext.dcloud.net.cn/plugin?name=uview-plus
3.修改main.js引入uview-plus
主要:
import uviewPlus from '@/uni_modules/uview-plus' app.use(uviewPlus)
完整main.js
import App from './App' // #ifndef VUE3 import Vue from 'vue' import './uni.promisify.adaptor' Vue.config.productionTip = false App.mpType = 'app' const app = new Vue({ ...App }) app.$mount() // #endif // #ifdef VUE3 import { createSSRApp } from 'vue' import uviewPlus from '@/uni_modules/uview-plus' export function createApp() { const app = createSSRApp(App) app.use(uviewPlus) console.log("222",uni.$u.config.v); return { app } } // #endif
4.根目录uni.scss,删除其它,写入
@import '@/uni_modules/uview-plus/theme.scss';
5.在App.vue
中首行的位置引入,注意给style标签加入lang="scss"属性
<style lang="scss"> /* 注意要写在第一行,同时给style标签加入lang="scss"属性 */ @import "@/uni_modules/uview-plus/index.scss";</style>
6.在uview-plus目录下,执行
npm i dayjs
以解决[vite]: Rollup failed to resolve import "dayjs/esm/index"
7.配置easycom组件模式(就不用import引入了)
在pages.json顶部加上代码
"easycom": { "autoscan": true, // 注意一定要放在custom里,否则无效,https://ask.dcloud.net.cn/question/131175 "custom": { "^u--(.*)": "@/uni_modules/uview-plus/components/u-$1/u-$1.vue", "^up-(.*)": "@/uni_modules/uview-plus/components/u-$1/u-$1.vue", "^u-([^-].*)": "@/uni_modules/uview-plus/components/u-$1/u-$1.vue" } },