在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/網(wǎng)絡(luò)安全/ 多個(gè)li標(biāo)簽,點(diǎn)擊展開當(dāng)前l(fā)i下隱藏的li內(nèi)容,再次點(diǎn)擊隱藏,vue如何實(shí)現(xiàn)???

多個(gè)li標(biāo)簽,點(diǎn)擊展開當(dāng)前l(fā)i下隱藏的li內(nèi)容,再次點(diǎn)擊隱藏,vue如何實(shí)現(xiàn)???

如圖點(diǎn)第一個(gè)li 所有l(wèi)i的p都會(huì)顯示。
點(diǎn)第二個(gè)li其他li隱藏內(nèi)容也展開了,怎么樣才能點(diǎn)哪個(gè)li,哪個(gè)li隱藏的li的內(nèi)容顯示呢?

clipboard.png

clipboard.png

代碼在這里:

<style>
  .box_li{
    padding: 0 40px;
    font-size: 20px;
    background-color: #bfbfbf;
    border: 1px solid #fff;
  }
  .after_p{
    background: bisque;
  }
</style>
<template>
  <div class="box">
    <ul v-for="item in items">
      <li class="box_li" @click="toggle()">
          <p>
            {{item.text}}
          </p>
      </li>
      <li>
        <p class="after_p" v-show="isActive" >
          {{item.desc}}
        </p>
      </li>
    </ul>
  </div>
</template>
<script>
  export default {
    data(){
      return{
        isActive: false,
        items: [{
          text: 'one',
          desc: 'one content',
        }, {
          text: 'two',
          desc: 'two conten'
        }, {
          text: 'three',
          desc: 'three conten'
        }]
      }
    },
    methods: {
      toggle() {
        this.isActive = !this.isActive;
      }
    },
  }
</script>
回答
編輯回答
咕嚕嚕

`data(){

        return{
            data: [],
            activeIndex: ''
        }
    }
    methods: {
        setIndex(index){
            this.activeIndex = index
        }
    }
    <div v-for="(item, index) in data">
        <li @click="setIndex(index)">
            <p v-show="index == activeIndex">{{item}}</p>
        </li>
    </div>`這就是手風(fēng)琴的實(shí)現(xiàn)原理
2018年5月4日 02:02
編輯回答
艷骨

用v-if 或者 v-show綁定一個(gè)變量 然后通過給變量賦值 (true or false)來實(shí)現(xiàn)控制顯示隱藏

2017年3月16日 20:49
編輯回答
久不遇

看你的需要,當(dāng)一個(gè)li展開的時(shí)候,其它li的狀態(tài)要不要變?
如果你只允許一個(gè)li展開,其它要收起。
那你可以把把 isActive 改成 activeIndex,當(dāng)點(diǎn)擊li的時(shí)候把a(bǔ)ctiveIndex修改為當(dāng)前的索引
li中內(nèi)容: v-show="activeIndex==index"

如果可以同時(shí)展開多個(gè),初始化的時(shí)候,你就要給每個(gè)item加上一個(gè)標(biāo)識(shí),每次點(diǎn)擊的時(shí)候修改這個(gè)標(biāo)識(shí)就可以了。

2017年9月14日 19:28