[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
小程序自带的一些组件有时候不能满足我们的一些需求,这个时候引入vant ui的组件是一个好的选择,今天详细说说使用这个vant ui的曲折过程。。。。
1.先在小程序中打开终端,使用npm init -y命令初始化,生成package.json文件
2.安装vant ui 依赖
# 通过 npm 安装 npm i @vant/weapp -S --production
3.点击右上角的详情,在本地配置中勾选使用npm模块
效果图:
3.根据vant ui官网要求 package.json 和 node_modules 必须在 miniprogram 目录下;所以我们使用工具让它自动生成
操作步骤:点击左上方的工具,选择构建npm
操作成功的效果图:
此时你的项目就成了这样:
那么引入vant ui的工作就做好了。
接下来简单说说使用
1.需要现在你的app.wxss文件中引入全局样式
@import '@vant/weapp/common/index.wxss';
2.然后再index.json或其他文件的json的usingComponents中引入组件
例如:
// 通过 npm 安装 { "usingComponents": { "van-button":
"/miniprogram_npm/@vant/weapp/button/index" } }
注:这里写的组件路径是在用npm生成的miniprogram文件夹中查找的
3.引入组件后,就可以在 wxml 中直接使用组件啦
<view> <van-button type="primary">按钮</van-button> </view>
那么最后引入组件的效果:
其实我第一次出现了一个报错:
这个报错的原因就是:我没有执行构建npm那一步,把package.json 和 node_modules 复制在 miniprogram 目录下。
今天就到这里了。大家可以都引入试试