VUE3.0引入vant组件库

目前Vant 3 是基于 Vue 3 开发的,在使用 Vant 3 前,请将项目中的 Vue 升级到 3.0 以上版本。

引入

通过 npm 安装
在现有项目中使用 Vant 时,可以通过npm或yarn安装

通过 npm 安装
npm i vant@next -S
通过 yarn 安装
yarn add vant@next

组件挂载

//main.js
import { createApp } from 'vue'
import App from './App.vue'
import './index.css'
import Vant from 'vant';
import 'vant/lib/index.css';

createApp(App).use(Vant).mount('#app')

组件使用

<template>
	<h1>test count: {{count}}</h1>
	<button @click="add">add</button>
	<van-button type="primary" size="large" url="/vant/mobile.html">URL 跳转</van-button>
	<van-button size="large" @click="print">print</van-button>
</template>

<script>
	import { ref } from 'vue'
	
	export default {
	  setup() {
	    const count = ref('1212')
	    const add = () => {
	      count.value++
	    }
	    const print = () => {
	      console.log(count.value)
	      console.log(import.meta.env.MODE)
	    }
	    return {
	      count,
	      add,
	      print
	    }
	  }
	}
</script>
  • 6
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 9
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值