VUE项目中安装和使用vant组件

mac2025-02-09  12

首先要搭建好vue脚手架:https://blog.csdn.net/qq_20757489/article/details/83718242

组件中文文档地址:https://youzan.github.io/vant/#/zh-CN/intro

1.使用NPM安装vant:

npm i vant -S

2.引入组件:使用 babel-plugin-import (推荐)

babel-plugin-import 是一款 babel 插件,它会在编译过程中将 import 的写法自动转换为按需引入的方式

# 安装 babel-plugin-import 插件 npm i babel-plugin-import -D

3.在.babelrc文件中配置plugins(插件)

"plugins": [ "transform-vue-jsx", "transform-runtime", ["import", [{ "libraryName": "vant", "style": true }]] ],

4、按需要引入vant组件,比如我们要在HelloWord.vue组件中使用 Loading 组件,我们可以先 在组件中引入 

<script> import { Loading } from 'vant' export default { components: { [Loading.name]: Loading } } </script>

5.然后在页面中加入组件代码

<template> <div> <van-loading color="black" /> <van-loading color="white" /> <van-loading type="spinner" color="black" /> <van-loading type="spinner" color="white" /> </div> </template>

这样就可以看到效果了

最新回复(0)