vue antd气泡卡片 在循环中 点击只展示一个(循环展示了多个气泡卡片)

 <a-table :columns="columns" :data-source="data">
    <a slot="name" slot-scope="text,record">{{ text }}</a>
    <span slot="action" slot-scope="text, record,index">
    <!-- 气泡卡片 -->
      <a-popover v-if="previewIndex==index" v-model="visible" title="预览(气泡卡片)" trigger="click">
         <div slot="content" >内容</div>
      </a-popover>
    <!-- 点击按钮 -->
       <a-button @click="preview(record,index)" type="primary">
          预览
       </a-button>
    </span>
  </a-table>

antd中按钮是在气泡卡片里面的,当我们使用表格的时候,把按钮从气泡卡片中分离出来,通过click事件控制显现

data(){
    return {
        visible: false, //因为重要是解决气泡卡片问题,表格的变量这里没有展示
        previewIndex:"", //将点击的数据的下标保存起来
    }
}
methods:{
    preview(record,index){
        this.previewIndex=index  //将点击的这条数据的下标保存起来
    }
}

然后用 v-if="previewIndex==index"判断 点击时的数据的下标 跟 表格循环里的数据的下标是否一致,一致就显示,不一致就不显示

如此,表格循环里展示多个气泡卡片就解决了

 

posted @ 2021-12-09 10:00  诗yu远方  阅读(548)  评论(0)    收藏  举报