欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 健康 > 养生 > vue3 选中对话框时,对话框右侧出一个箭头

vue3 选中对话框时,对话框右侧出一个箭头

2025/2/24 3:43:02 来源:https://blog.csdn.net/zhaofuqiangmycomm/article/details/143240516  浏览:    关键词:vue3 选中对话框时,对话框右侧出一个箭头

先看下做出的效果:

html代码,其中listPlan.records是后台拿到的数据进行遍历

<template><ul class="list"><li  style="height: 180px;width: 95%":key="index"v-for="(item, index) in listPlan.records":style="liStyle(index)"@click="selectItem(index,item.id)" ><span v-if="selectedIndex === index" class="shixin"></span><span v-if="selectedIndex === index" class="kongxin"></span><div   class="notice"><div class="fsPnameDiv"><div  class="fsPname" >{{ item.fsPname }}</div><div v-if="item.fsStatus=='00'" style="color: #0a8fe9"><span class="ant-badge-status-dot" style="background: rgb(68, 160, 239);"></span>激活</div><div v-if="item.fsStatus!='00'" style="color: rgb(208 213 217)"><span class="ant-badge-status-dot" style="background: rgb(208 213 217);"></span>禁用</div></div><div style="margin-top: 5px">每隔{{ item.fsExecinterval }}  {{ item.fsExecintervaltype  }} 执行一次</div><div style="margin-top: 5px">创建时间:{{ item.createTime }}</div></div></li></ul></template>

ts代码

原理:选中时判断比较选中的下标是和循环中的游标一致改变样式

let planId=null;// 当前选中的索引
const selectedIndex = ref(-1);
// 动态生成 li 的样式
const liStyle = (index: number) => {return {border: '1px solid #ccc', // 添加边框borderRadius: '5px',padding: '10px', // 内边距margin: '5px 0', // 外边距cursor: 'pointer', // 鼠标指针样式position: 'relative', // 相对定位,用于放置箭头borderLeft: selectedIndex.value === index ? '2px solid rgb(9 95 240)' : '1px solid #ccc', // 选中时的框样式borderBottom: selectedIndex.value === index ? '2px solid rgb(9 95 240)' : '1px solid #ccc',borderTop: selectedIndex.value === index ? '2px solid rgb(9 95 240)' : '1px solid #ccc',borderRight: selectedIndex.value === index ? '2px solid rgb(9 95 240)' : '1px solid #ccc',};
};

css

原理:无大小的div设置30px的边框全透明,再单独设置要显示一侧边框的颜色和大框一致

<style lang="less" scoped>.notice{align-items: flex-start;display: flex;flex-direction: column;padding: 8px 8px 12px;
}.shixin {border: 10px solid transparent;border-left-color: #095ff0;position: absolute;top: 45%;right: -20px;
}
.kongxin {border: 10px solid transparent;border-left-color: #fff;position: absolute;top: 45%;right: -18px;
}
</style>

参考:通过css画出带箭头的提示框 - 简书

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词