vue3 全局引入 vant
时间: 2023-08-24 15:08:50 浏览: 126
要在Vue3中全局引入Vant组件库,你可以按照以下步骤进行操作:
1. 在终端中使用npm安装Vant组件库:`npm i vant`
2. 在`main.js`文件中导入Vant并引入其样式文件:
```javascript
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import vant from 'vant';
import 'vant/lib/index.css';
createApp(App).use(router).use(vant).mount('#app')
```
3. 现在你可以在其他Vue组件中直接使用Vant组件了。例如,在一个.vue文件中:
```html
<template>
<div>
<van-button type="primary">主要按钮</van-button>
<van-button type="success">成功按钮</van-button>
<van-button type="default">默认按钮</van-button>
<van-button type="warning">警告按钮</van-button>
<van-button type="danger">危险按钮</van-button>
</div>
</template>
<script setup>
</script>
<style lang="less" scoped>
</style>
```
这样就完成了在Vue3中全局引入Vant组件库的操作。你可以在需要的地方使用Vant的组件了。
#### 引用[.reference_title]
- *1* [vue3全局引入vant](https://blog.csdn.net/jjw_zyfx/article/details/129489147)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* *3* [(填坑篇)Vue3.0全局引入Vant组件](https://blog.csdn.net/a1037949156/article/details/123244368)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文