官网

1.基本使用

  1. 1.安装Vant UI
  2. npm i vant -S
  3. 2.main.js 导入MintUI,并注册到Vue
  4. import Vue from 'vue'
  5. //全局引入Vant UI的样式以及组件库
  6. import 'vant/lib/index.css';
  7. import Vant from 'vant';
  8. Vue.use(Vant);
  9. var vm = new Vue({
  10. el: '#app',
  11. data: {
  12. msg: '123'
  13. },
  14. render:e=>e(app)
  15. })
  16. 3.app.vue
  17. <template>
  18. <div>
  19. <van-button type="default" @click="showPopup">默认按钮</van-button>
  20. <van-button type="primary">主要按钮</van-button>
  21. <van-button type="info">信息按钮</van-button>
  22. <van-button type="warning">警告按钮</van-button>
  23. <van-button type="danger">危险按钮</van-button>
  24. <van-popup v-model="show">内容</van-popup>
  25. </div>
  26. </template>

2.按需导入

  1. //1.安装babel-plugin-import插件
  2. npm i babel-plugin-import -D
  3. //2.修改babel的配置文件
  4. {
  5. "presets": [
  6. "env",
  7. "stage-0"
  8. ],
  9. "plugins": [
  10. "transform-runtime",
  11. [
  12. "import",
  13. {
  14. "libraryName": "vant",
  15. "libraryDirectory": "es",
  16. "style": true
  17. }
  18. ]
  19. ]
  20. }
  21. //3.修改main.js
  22. //按需加载 用到什么就去引入什么
  23. import { Button,Popup,Form,Field } from 'vant';
  24. Vue.use(Button);
  25. Vue.use(Popup);
  26. Vue.use(Form);
  27. Vue.use(Field);

babel版本配置错误解决方案