UniApp开发H5引入Vant

第一步:下载安装vant

npm i vant -S --production

第二步:main.ts引入Vant

import {createSSRApp} from 'vue'

import App from './App.vue'
// 引入Vant
import Vant from "vant";

export function createApp() {
    const app = createSSRApp(App).use(Vant)
    return {
        app,
    }
}

不管是js还是ts,Vue.use()他就对了

也可以结构后按需导入

import {Button,......} from "vant"

Vue.use(Button)

第三步:App.vue中引入全局样式,两种import都试试,里面坑多

<style>
/*每个页面都引入Vant*/
/*@import url("./node_modules/vant/lib/index.css");*/
@import "vant/lib/index.css";
</style>

第四步:就可以使用它了

Vant 3 - Lightweight Mobile UI Components built on VueLightweight Mobile UI Components built on Vuehttps://vant-contrib.gitee.io/vant/#/zh-CN

猜你喜欢

转载自blog.csdn.net/weixin_42078172/article/details/127402299
今日推荐