serainleo-mp-ui
v1.0.1-beta.3
Published
mp-ui
Downloads
4
Readme
mp-ui
安装及配置
关于SCSS
mp-ui依赖SCSS,您必须要安装此插件,否则无法正常运行。
- 如果您的项目是由
HBuilder X
创建的,相信已经安装scss插件,如果没有,请在HX菜单的 工具->插件安装中找到"scss/sass编译"插件进行安装, 如不生效,重启HX即可 - 如果您的项目是由vue-cli创建的,请通过以下命令安装对sass(scss)的支持,如果已安装,请略过。
// 安装sass
npm i sass -D
// 安装sass-loader,注意需要版本10,否则可能会导致vue与sass的兼容问题而报错
npm i sass-loader@10 -D
准备工作
在进行配置之前,请确保您已对mp-ui进行了npm安装,如果没有,请先执行安装:
// 如果您的项目是HX创建的,根目录又没有package.json文件的话,请先执行如下命令:
// npm init -y
// 安装
npm install @swsc/mp-ui
配置
配置easycom组件模式
此配置需要在项目src
目录的pages.json
(使用了uni-simple-router的项目为pages.js
)中进行。
:::tip 温馨提示
- uni-app为了调试性能的原因,修改
easycom
规则不会实时生效,配置完后,您需要重启HX或者重新编译项目才能正常使用mp-ui的功能。 - 请确保您的
pages.json
中只有一个easycom
字段,否则请自行合并多个引入规则。 :::
// pages.json
{
"easycom": {
"autoscan": true,
"custom": {
"^u-(.*)": "uview-ui/components/u-$1/u-$1.vue",
"^sw-(.*)": "@swsc/mp-ui/components/sw-$1/sw-$1.vue",
"^uni-(.*)": "@dcloudio/uni-ui/lib/uni-$1/uni-$1.vue"
}
},
// 此为本身已有的内容
"pages": [
// ......
]
}
引入mp-ui的全局SCSS主题文件
在项目src
目录的uni.scss
中引入此文件。
/* uni.scss */
@import '@swsc/mp-ui/theme.scss';
3. 引入mp-ui基础样式
:::danger 注意!
在App.vue
中首行的位置引入,注意给style标签加入lang="scss"属性
:::
<style lang="scss">
@import "@swsc/mp-ui/index.scss";
</style>