
vue中,这个点击左边进度条,右边内容切换,进度条背景右边框蓝色线,并且带有三角形如何实现,这个东西叫什么名字
关注引自免费微信小程序:皆我百晓生
在Vue.js中,您可以通过监听左侧进度条的点击事件,并结合动态样式绑定(v-bind:style)来实现进度条切换时右侧内容更新以及进度条背景右边框的蓝色线条和三角形指示器。下面是一个简化的示例实现方案:
首先,我们需要一个数据结构来存储每个进度条项的状态,包括名称、进度值以及当前选中状态:
data() {
return {
progressItems: [
{ name: 'speedlimit', value: 91.03, selected: true },
{ name: 'erosswalk', value: 0.00, selected: false },
{ name: 'trafficlight', value: 0.00, selected: false },
{ name: 'stop', value: 0.00, selected: false }
],
currentSelectedIndex: 0,
// 其他可能需要的变量...
};
},
接下来,在模板中渲染左侧的进度条和右侧的内容:
<template>
<div class="progress-container">
<div class="progress-bar" v-for="(item, index) in progressItems" :key="index"
@click="selectItem(index)"
:class="{ 'selected': index === currentSelectedIndex }"
:style="{ 'width': `${item.value}%`, 'border-right': `5px solid ${item.selected ? 'blue' : 'transparent'}` }">
<!-- 三角形指示器,这里采用伪元素实现 -->
<div class="indicator" v-if="item.selected"></div>
{{ item.name }}
{{ item.value }}%
</div>
<div class="content">
<div v-if="progressItems[currentSelectedIndex].name === 'speedlimit'">对应speedlimit的相关内容...</div>
<!-- 其他内容区域的渲染 -->
</div>
</div>
</template>
<style scoped>
.progress-container {
display: flex;
}
.progress-bar {
position: relative;
background-color: #eee;
height: 30px;
line-height: 30px;
text-align: center;
cursor: pointer;
overflow: hidden;
transition: border-color 0.3s;
}
.progress-bar.selected::before {
content: '';
position: absolute;
top: 50%;
transform: translateY(-50%);
right: -20px;
width: 0;
height: 0;
border-top: 10px solid transparent;
border-bottom: 10px solid transparent;
border-left: 10px solid blue;
}
.indicator {
position: absolute;
right: -10px;
top: 50%;
transform: translateY(-50%);
width: 0;
height: 0;
border-top: 10px solid transparent;
border-bottom: 10px solid transparent;
border-left: 10px solid blue;
}
</style>
在此示例中,当用户点击进度条时,selectItem 方法会被调用,更新当前选中的进度条索引,并根据此索引更新对应的右侧内容显示。同时,通过:style绑定动态修改选中进度条的右边界颜色为蓝色,并利用CSS伪元素创建一个三角形指示器。
以上代码仅为示例,实际应用时您可能需要根据具体需求进行调整。