VUE项目中安装和使用vant组件
📅 2026/7/4 10:15:28
👁️ 阅读次数
📝 编程学习
VUE项目中安装和使用vant组件
Vant 是有赞前端团队基于有赞统一的规范实现的 Vue 组件库,提供了一整套 UI 基础组件和业务组件。
组件中文文档地址:https://youzan.github.io/vant/#/zh-CN/home
1、创建VUE项目之后进入项目目录运行安装命令:
npm i vant-S2、安装 babel-plugin-import 插件,babel-plugin-import 是一款 babel 插件,它会在编译过程中将 import 的写法自动转换为按需引入的方式
npm i babel-plugin-import-D3、在.babelrc文件中配置plugins(插件)
"plugins":["transform-vue-jsx","transform-runtime",["import",[{"libraryName":"vant","style":true}]]],4、按需要引入vant组件,比如我们要在HelloWord.vue组件中使用 Loading 组件,我们可以先 在组件中引入
<script>import{Loading}from'vant'exportdefault{components:{[Loading.name]:Loading}}</script>然后在页面中加入组件代码
<template><div><van-loading color="black"/><van-loading color="white"/><van-loading type="spinner"color="black"/><van-loading type="spinner"color="white"/></div></template>这样就可以看到效果了
文章参考链接:https://blog.csdn.net/ansu2009/article/details/80682920
编程学习
技术分享
实战经验