npm i vant
"dependencies": {
"vant": "^4.0.8",
"vue": "^3.2.45"
}
// 1. Import the components you need
import { Button } from 'vant';
// 2. Import the components style
import 'vant/lib/index.css';
// 3. Use the components
createApp(App).use(Button).mount('#app')
import Vant from 'vant'; import 'vant/lib/index.css'; app.use(Vant);
<van-button type="primary">Primary</van-button>
npm i amfe-flexible
import "amfe-flexible";
npm install postcss postcss-pxtorem --save-dev
// postcss.config.js
export default {
plugins: {
"postcss-pxtorem": {
// 设计稿宽度;默认是350px
rootValue: 37.5,
// 需要转化的 CSS 属性
propList: ["*"],
},
},
};
// 1. Import the components you need
import { Tabbar, TabbarItem } from 'vant';
// 2. Import the components style
import 'vant/lib/index.css';
createApp(App).use(Tabbar).use(TabbarItem).mount('#app')
import h5 from "../assets/html-5.png"
import unity from "../assets/unity.png"
const active = ref(0);
const icon = {
active: h5,
inactive: unity,
};
<van-tabbar v-model="active" active-color="#f46">
<van-tabbar-item>
<span>Menu</span>
<template #icon="props">
<img :src="props.active ? icon.active : icon.inactive" />
</template>
</van-tabbar-item>
<van-tabbar-item icon="fire" dot>Search</van-tabbar-item>
<van-tabbar-item icon="setting-o" badge="5">Setting</van-tabbar-item>
</van-tabbar>
const icon = {
active: url,
inactive: url,
};