当前位置:网站首页>在uni-app中引入uView
在uni-app中引入uView
2022-07-02 05:54:00 【Serena_tz】
在uni-app中引入uView的方式有两种:
通过npm下载
// 如果您的根目录没有package.json文件的话,请先执行如下命令:
// npm init -y
npm install uview-ui
// 更新
// npm update uview-ui
配置步骤
1.引入uView主JS库
在项目根目录中的main.js中,引入并使用uView的JS库,注意这两行要放在import Vue之后。
// main.js
// 引入全局 uView 框架
import uView from 'uview-ui';
Vue.use(uView);
2.在引入uView的全局SCSS主题文件
在项目根目录的uni.scss中引入此文件。
/* uni.scss引入view主题样式 */
@import 'uview-ui/theme.scss';
3.引入uView基础样式
注意:在App.vue中首行的位置引入,注意给style标签加入lang="scss"属性
<style lang="scss">
/* 注意要写在第一行,同时给style标签加入lang="scss"属性 */
@import "uview-ui/index.scss";
</style>
4.配置easycom组件模式
在pages.json配置,uni-app为了调试性能的原因,修改easycom规则不会实时生效,配置完后,您需要重启Hbuilder X或者重新编译项目才能正常使用uView的功能。请确保您的pages.json中只有一个easycom字段,否则请自行合并多个引入规则。
"easycom": {
"^u-(.*)": "uview-ui/components/u-$1/u-$1.vue"
},
通过插件市场安装
如果使用Hbuilder X进行开发,就可以在uni-app插件市场通过uni_modules的形式进行安装。
1.点击导入
2.打开hbuilderX
3.选择项目
4.开始下载
5.确保安装了scss/sass编译器
在工具中找到“插件安装”
配置步骤
1.引入uView主JS库
在项目根目录中的main.js中,引入并使用uView的JS库,注意这两行要放在import Vue之后。
// main.js
import uView from '@/uni_modules/uview-ui'
Vue.use(uView
2.在引入uView的全局SCSS主题文件
在项目根目录的uni.scss中引入此文件。
/* uni.scss */
@import '@/uni_modules/uview-ui/theme.scss';
3.引入uView基础样式
注意:在App.vue中首行的位置引入,注意给style标签加入lang="scss"属性
<style lang="scss">
/* 注意要写在第一行,同时给style标签加入lang="scss"属性 */
@import "@/uni_modules/uview-ui/index.scss";
</style>
4.配置easycom组件模式
在pages.json配置,uni-app为了调试性能的原因,修改easycom规则不会实时生效,配置完后,您需要重启Hbuilder X或者重新编译项目才能正常使用uView的功能。请确保您的pages.json中只有一个easycom字段,否则请自行合并多个引入规则。uni_modules方式引入的uview可以不配置。
"easycom": {
"^u-(.*)": "@/uni_modules/uview-ui/components/u-$1/u-$1.vue"
},
边栏推荐
- 5g market trend in 2020
- JS determines whether the mobile terminal or the PC terminal
- vite如何兼容低版本浏览器
- Test case
- RGB infinite cube (advanced version)
- 外部中断无法进入,删代码再还原就好......记录这个想不到的bug
- Addchild() and addattribute() functions in PHP
- CNN可视化技术 -- CAM & Grad-CAM详解及pytorch简洁实现
- all3dp.com网站中全部Arduino项目(2022.7.1)
- 数理统计与机器学习
猜你喜欢
File contains vulnerabilities (II)
Happy Lantern Festival | Qiming cloud invites you to guess lantern riddles
Software testing learning - day 4
2022-2-14 learning xiangniuke project - Section 7 account setting
idea开发工具常用的插件合集汇总
[personal test] copy and paste code between VirtualBox virtual machine and local
OLED12864 液晶屏
5g market trend in 2020
Technologists talk about open source: This is not just using love to generate electricity
A collection of commonly used plug-ins for idea development tools
随机推荐
cookie插件和localForage离线储存插件
Test case
VSCode paste image插件保存图片路径设置
2022-2-14 learning xiangniuke project - Section 6 displays login information
idea開發工具常用的插件合集匯總
Redis Key-Value数据库 【高级】
Fundamentals of software testing
JS determines whether the mobile terminal or the PC terminal
Zzuli: maximum Convention and minimum common multiple
Can't the dist packaged by vite be opened directly in the browser
Common protocols and download paths of NR
ESP8266与STC8H8K单片机联动——天气时钟
RGB 无限立方体(高级版)
PHP obtains some values in the string according to the specified characters, and reorganizes the remaining strings into a new array
Addchild() and addattribute() functions in PHP
【C语言】筛选法求素数
RNN recurrent neural network
测试 - 用例篇
php内的addChild()、addAttribute()函数
OLED12864 液晶屏