zoukankan      html  css  js  c++  java
  • vue-music 关于基础组件 (Tab组件)

     

    定义在项目的基础组类别的 tab组件中,定义一个tab切换数量的数组 和一个currentIndex 当前高亮索引 的props,当前高亮(active)的类等于currentIndex === index 当前循环的索引值,增加点击派发事件传入index 索引参数,

    调用组件的页面接受派发事件点击的index 索引,底下的内容根据this.currentIndex 的值v-if 显示隐藏

    tab组件

    <template>
      <ul class="switches">
        <li class="switch-item" v-for="(item,index) in switches" :class="{'active':currentIndex === index}"
            @click="switchItem(index)">
          <span>{{item.name}} </span>
        </li>
      </ul>
    </template>
    
    <script type="text/ecmascript-6">
      export default {
        props: {
          switches: {
            type: Array,
            default: []
          },
          currentIndex: {
            type: Number,
            default: 0
          }
        },
        methods: {
          switchItem(index) {
            this.$emit('switch', index)
          }
        }
      }
    </script>

    调用

    <switches :switches="switches" :currentIndex="currentIndex" @switch="switchItem"></switches>

    data() {
      return {
        currentIndex: 0,
        switches: [
          {
            name: '最近播放'
          },
          {
            name: '搜索历史'
          }
        ]
      }
    },
    
    switchItem(index) {
      this.currentIndex = index
    },
  • 相关阅读:
    Java虚拟机:二、Java内存区域
    Filter模块插件的详细介绍
    Input模块插件的详细介绍
    Logstash的简单介绍
    Logstash的下载安装
    安装Ruby和logstash插件
    Kibana安装与web界面
    ElasticSearch的下载安装
    Flink项目点 pom文件
    IDEA的配置
  • 原文地址:https://www.cnblogs.com/inzaghihao/p/7985722.html
Copyright © 2011-2022 走看看