vue3怎么createApp方法挂载vant的组件
时间: 2024-05-05 14:17:16 浏览: 259
vue3源码之createApp
要在Vue3中使用Vant组件,需要先安装Vant:
```
npm install vant -S
```
然后,在main.js中引入Vant:
```
import { createApp } from 'vue'
import Vant from 'vant';
import 'vant/lib/index.css';
import App from './App.vue'
const app = createApp(App)
app.use(Vant)
app.mount('#app')
```
注意,要同时引入Vant的样式文件。然后,你就可以在Vue组件中使用Vant组件了。例如,在App.vue中使用Button组件:
```
<template>
<div>
<van-button @click="handleClick">按钮</van-button>
</div>
</template>
<script>
export default {
name: 'App',
methods: {
handleClick() {
console.log('按钮被点击了')
}
}
}
</script>
```
阅读全文