webpack中‘vant’全局引入和按需引入【vue-cli】

一、安装

npm i vant -S

 

二、引入

1.全局引入

import Vue from 'vue'
import Vant from 'vant'
import 'vant/lib/index.css'

Vue.use(Vant)

 

2.按需引入

// 1.需要先安装npm install babel-plugin-import -D
// 2.在babelrc中配置
   "plugins": [
    "transform-vue-jsx",
    "transform-runtime",
    ["import", [
      {
        "libraryName":"vant",
        "style":true
      }
      ]
    ]
  ]     

import { Button } from 'vant'

Vue.use(Button)

 

转载于:https://www.cnblogs.com/jackjo/p/10072106.html

你可能感兴趣的:(webpack中‘vant’全局引入和按需引入【vue-cli】)