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"
After successful construction, it will prompt:
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.
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:
{
"usingComponents":{
"van-button":"/miniprogram_npm/vant-weapp/button/index"
}
}
Then you can directly call this ui component in wxml.
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!