Use cli to build the uni-app project and introduce vant

github site: w-uniapp-vant

first step

  • Install vue-cli globally
npm install -g @vue/cli
  • Create uni-app and use the official version (corresponding to the latest official version of HBuilderX)
vue create -p dcloudio/uni-preset-vue my-project

At this time, you will be prompted to select a project template (you will not be prompted when using the Vue3/Vite version. Currently, only the creation of default templates is supported). For first-time experience, it is recommended to select the hello uni-app project template, as shown below: I chose it here It isTypeScript template
Insert image description here
and the structure is like this
Insert image description here

  • Next download vant
npm i @vant/weapp -S --production
  • Create a new folder in the root directorywxcomponents and then find the dist under vant/weapp in node_mpdules and copy it to wxcomponents (mine is Replace the dist folder name with vant)
  • Insert image description hereInsert image description here
  • Introduce components below pages.json as shown below
    Insert image description here
"usingComponents": {
    
    
	"van-button": "../wxcomponents/vant/button/index"
}
  • and then use
<view>
	<van-button type="primary">默认按钮</van-button>
	<van-button type="info">信息按钮</van-button>
	<van-button type="warning">警告按钮</van-button>
	<van-button type="danger">危险按钮</van-button>
</view>

Insert image description here

  • You will see the following interface
    Insert image description here
    You may encounter blank related issues when packaging and publishing online
    It is similar to vue, just modify it here (manifest.json)
    Insert image description here
    I have tried publishing it online and no problem
    The next article will be published to the mini program~

Guess you like

Origin blog.csdn.net/weixin_43867229/article/details/134333309