vue项目全局组件

本文介绍了一个基于Vue的公共组件——底部导航栏的实现。该组件使用了v-for循环展示底部菜单项,通过@click事件跳转到不同的页面,并且能够切换选中状态的图片。组件还包含了自定义的方法和样式,适用于多种应用场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

公共组件

<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'
//注册组件,通过公共组件的name调用
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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

✎﹏ℳ๓敬坤

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值