公共组件
<template>
<div class="bottom-box">
<div v-for="(item,index) in bottomArray" :key="index" @click="goUrl(item.url)">
<img :src="active==index?item.selectImg:item.backgoundImg" alt="">
{{item.title}}
</div>
</div>
</template>
<script>
export default {
name: 'homeBottom',
props:['active'],
data(){
return {
bottomArray:[
{title:'行情',selectImg:require('../assets/bottom/hangqing-select.png'),backgoundImg:require('../assets/bottom/hangqing.png'),url:'/quotes'},
{title:'策略',selectImg:require('../assets/bottom/celve-select.png'),backgoundImg:require('../assets/bottom/celve.png'),url:'/strategy'},
{title:'社区',selectImg:require('../assets/bottom/zhitu-select.png'),backgoundImg:require('../assets/bottom/zhitu.png'),url:'/community'},
{title:'试炼场',selectImg:require('../assets/bottom/zsc-select.png'),backgoundImg:require('../assets/bottom/zsc.png'),url:'/provingGround'},
{title:'我的',selectImg:require('../assets/bottom/my-select.png'),backgoundImg:require('../assets/bottom/my.png'),url:'/mine'},
]
}
},
methods:{
goUrl(val){
this.$router.push(val);
}
}
}
</script>
<style lang="scss" scoped>
.bottom-box{
position: fixed;
bottom: 0;
height: 50px;
left: 0;
width: 100%;
display: -webkit-flex;
display: flex;
-webkit-justify-content: space-between;
justify-content: space-between;
border-top: 1px solid #ccc;
div{
width: 20%;
height: 50px;
text-align: center;
font-size: 12px;
img{
width: 20px;
height: 20px;
display: block;
margin: 5px auto;
}
}
}
</style>
main.js配置
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import homeBottom from '@/components/bottom.vue'
Vue.component("home-bottom",homeBottom)
Vue.config.productionTip = false
new Vue({
router,
render: h => h(App),
}).$mount('#app')
需要调用组件的页面
<home-bottom></home-bottom>