VUE.JS+KOA2 Mobile e-commerce combat 2

Source: Internet
Author: User
Tags button type

introducing the Vant component library

In the work, there are many of their own library of components, but before the development of these will choose a stable set of open source as a wheel as the basis (big companies are capable of making their own wheels). Because we want to be an e-commerce system, we chose the vant as the basic component and styling component of Vue.

 Installing Vant
NPM I Vant-s

Once installed, take a look at our Package.json file and confirm the version.

First method of introducing vant (not recommended)

Once vant is installed, it can be introduced using previously used methods-a way to introduce it globally.
The global introduction is done directly in Src/main.js.

Import vant from ' vant' vant/lib/vant-css/index.css 'vue.use (vant)

Simple three lines of code can already be introduced into the vant, but this is not elegant, also makes the final package release will increase the size of the packet, Vue's spa first screen opened when the original is somewhat slow, so it is not recommended to use this method to introduce.

Elegant introduction of Vant

Vant is a support for Babel-plugin-import introduced, it allows us to introduce component modules on demand, and does not manage our style, now the main introduction method of Vue Project component library.
Installing Babel-plugin-import

NPM I babel-plugin-import-d

Configuring plugins (Plug-in) in. BABELRC

"Plugins": [    "Transform-vue-jsx",     "Transform-runtime",    ["import", {" LibraryName ":" Vant "," style ":true}]  ]
Use Vant components on demand

After we set up the. BABELRC, the Vant framework can be introduced as needed. For example, now we're introducing a Button component.
Add the following code to the Src/main.js:

Import {Button} from ' Vant '

With this code, we can add in the required component page Button .

<van-button type= "PRIMARY" > main buttons </van-button>

VUE.JS+KOA2 Mobile e-commerce combat 2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.