How to correctly use vant ui components in WeChat applet development

The WeChat applet can finally support npm to import third-party libraries ( https: //developers.weixin.qq .... ), but this import mode and usage mode are different from the npm calls we use. Today, I will explain how to import npm resources according to the new vant applet ui library.

first step:

Execute in the root directory of the applet project:

npm and vant-weapp -S --production

The second step:

Make sure your WeChat developer tool is the latest version, then click to execute "Build npm"
20180912230952_76073.png

After successful construction, it will prompt:
20180912230949_96978.png

At the same time, there will be an additional directory "miniprogram_npm" in the root directory of the project. This is the npm third-party library recognized by the applet.

20180912230907_21498.png

third step:

At this time, when we need to call the vant component in a page, we must add the following configuration to the corresponding page json:
20180912230905_91838.png

{

"usingComponents":{

    "van-button":"/miniprogram_npm/vant-weapp/button/index"

}

}

Then you can directly call this ui component in wxml.
20180912230903_52769.png

Note that for the vant library, you actually don't need to require the vant-weapp component in the js corresponding to the page.

First published in my blog: http: //www.leeon.me/a/use-van ... , please indicate when reprinted!

Guess you like

Origin www.cnblogs.com/baimeishaoxia/p/12696409.html