需要引入第三方UI组件 Vant-Weapp
一、初始化,输入命令npm init
打开终端,输入cd 拖拽项目文件到终端,然后输入命令npm init

此时,输入package name名称,一直点回车就行


出现Is this OK?(yes),直接回车即可
二、安装第三方组件
在终端输入命令npm i vant-weapp -S --production

在回过头看,在微信小程序开发工具中会多一个文件package.json,在这里面就可以进行包的配置。
三、在小程序开发工具中选择左上栏的“工具”->“构建npm”


这个时候可以在项目文件夹中看见一个新生成的文件夹miniprogram_npm,其中就有我们刚刚安装好的vant组件库

四、小程序开发工具中,点击右上角的“详情”,将“使用npm模块”勾选上

五、在需要使用该组件库的页面中的json文件中,添加需要使用的组件中的内容(以button为例)

这里要注意,一定是将引入的第三方组件写入“usingComponents”的字典中,如果写成平级的话,会提示page.json [vant-button]无效
六、在wxml页调用组件库
<vant-button type="danger">微信登陆</vant-button>
网友评论