Vue2.0 实现单选互斥的方法

2019-11-16,,

本文介绍了Vue2.0 实现单选互斥的方法,分享给大家,具体如下:

需要实现如上图的功能

1. 首次加载页面,根据data里的catgoryId高亮对应的选项
2. 点击某个选项,该选项高亮,其他去掉高亮

代码结构:

<template> 
  <dd @click="changeCategory(currCourseFirst.categoryId)" 
        v-for="currCourseFirst in currCourse.currCourseFirst" 
        :key="currCourseFirst.categoryId" 
        :class="resultCategoryId === currCourseFirst.categoryId ? 'active': ''" >
          {{currCourseFirst.name}}
  </dd>
</template>

<script>
  export default{
    data() {
      return {
        categeryId: this.$route.query.categoryId,
        typeId: this.$route.query.typeId
      }
    },
    methods: {
      changeCategoryId(categoryId) {
        this.categoryId = categoryId
      }
    },
    computed: {
      resultCategoryId(){
        return this.categoryId
      }
    }
  }
</script>

自我理解

参考链接://www.kunjuke.com/article/138185.htm

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持北冥有鱼。

您可能感兴趣的文章:

  • 用vue2.0实现点击选中active其他选项互斥的效果

《Vue2.0 实现单选互斥的方法.doc》

下载本文的Word格式文档,以方便收藏与打印。