el-tooltip点击后才显示内容

<div class="stock" v-for="(item, index) in dataList" :key="index">
	<el-tooltip effect="dark" placement="top" manual :ref="'tooltip-' + item.id">
		<div slot="content">
			<!-- 点击后才显示的内容写在这里 -->
			编号: {{ item.code }}
			{{ popoverList }}
		</div>
		<div class="tooltip" @click="handleClickView(item.id)">
            <!-- 外层内容写在这里 --> 
            <div>点击查看数据</div>  
		</div>
	</el-tooltip>
 </div>
data() {
	return {
		dataList: [
			{id: 1, code: '123'},
			{id: 2, code: '145'},
			{id: 3, code: '125'},
		],
		popoverList: null,
		clickId: ''
	}
},
created() {
	document.addEventListener('click', this.handleClick)
},
methods: {
	// 点击其它地方隐藏tooltip
	handleClick() {
      if (this.clickId === '') {
        return
      } else {
        this.$refs[`${'tooltip-' + this.clickId}`][0].showPopper = !this.$refs[`${'tooltip-' + this.clickId}`][0].showPopper
        this.clickId = ''
      }
    },
	// 点击对应的框触发
	handleClickView(id) {
		getById(id).then(res => {
		 	if (res.code === 0) {
		 		  this.popoverList = res.data
		 		  this.clickId = id
		 		  // 获取到含有'tooltip'关键词且不含当前id的refs,
		 		  const refsWithKeyword = this.getRefsWithKeyword('tooltip', id)
		 		  // 将所有获取到的refs中的tooltip隐藏
		          refsWithKeyword.forEach(item => {
		            item[0].showPopper = false
		          })
		          // 只切换当前的tooltip显示/隐藏
		          this.$refs[`${'tooltip-' + id}`][0].showPopper = !this.$refs[`${'tooltip-' + id}`][0].showPopper
		 	}
		})
	},
	getRefsWithKeyword(keyword, id) {
      return Object.keys(this.$refs)
        .filter(refName => refName.includes(keyword) && !refName.includes(id))
        .map(refName => this.$refs[refName]);
    },
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值