效果
步骤
- 下载
// Vue
// # Vue 2 项目,安装 Vant 2:
npm i vant -S
// # Vue 3 项目,安装 Vant 3:
npm i vant@next -S
- 自动按需引入组件
// # npm
npm i babel-plugin-import -D
// # yarn
yarn add babel-plugin-import -D
- 配置及引入
- 配置按需引入
// babel.config.js
module.exports = {
presets: [
'@vue/cli-plugin-babel/preset'
],
plugins: [
['import', {
libraryName: 'vant',
libraryDirectory: 'es',
style: true
}, 'vant']
]
}
- 使用
// srv/views/Layout/index.vuw
<template>
<div>
<!-- 二级路由 - 挂载点 -->
<router-view></router-view>
<van-tabbar route>
<van-tabbar-item replace to="/layout/home" icon="home-o">首页</van-tabbar-item>
<van-tabbar-item replace to="/layout/search" icon="search">搜索</van-tabbar-item>
</van-tabbar>
</div>
</template>
<script>
export default {
data () {
return {
active: 0,
}
},
};
</script>
<style scoped>
/* 中间内容区域 - 容器样式(留好上下导航所占位置) */
.main {
padding-top: 46px;
padding-bottom: 50px;
}
</styles>