vue中點擊顯示不同的狀態


<template>
    <div>
        <div @click="choosetype" class="searchbox">
            <span :class="curtype==1?'active':''" data-i="1">熱銷專區</span>
            <span :class="curtype==2?'active':''" data-i="2">水果蛋糕</span>
            <span :class="curtype==3?'active':''" data-i="3">網紅蛋糕</span>
            <span :class="curtype==4?'active':''" data-i="4">千層蛋糕</span>
          </div>
    </div>
</template>
<script>
 
    export default {


        data() {
            return {
               curtype:1,//默認顯示第一個
            }

        },
        methods:{
              choosetype(e){
                  console.log(111)
                  if(e.target.nodeName=="SPAN"){
                       this.curtype=e.target.dataset.i
                  }
              }
        }
       
        
    };


</script>
<style>
    /* 搜索專區 */
 .searchbox {
    display: flex;
    align-items: center;
    padding: 0 0.16rem;
    margin: 0.15rem 0;
    color: pink;
    font-size: 0.14rem;
  }
  /* 點擊顯示樣式 */
  .searchbox span {
    margin-left: 0.2rem;
  }

  .searchbox .active {
    font-size: 0.18rem;
    font-weight: 600;
  }

  .searchbox img {
    width: 0.2rem;
    height: 0.2rem;
  }
</style>

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM