修复分段器动态赋值不生效的bug

This commit is contained in:
qixv-0506
2023-08-08 21:40:14 +08:00
parent 9578de3358
commit 712d73d2b0
@@ -1,31 +1,19 @@
<template>
<view
class="tn-subsection-class tn-subsection"
:class="[subsectionBackgroundColorClass]"
:style="[subsectionStyle]"
>
<view class="tn-subsection-class tn-subsection" :class="[subsectionBackgroundColorClass]"
:style="[subsectionStyle]">
<!-- 滑块 -->
<block v-for="(item, index) in listInfo" :key="index">
<view
class="tn-subsection__item tn-text-ellipsis"
:class="[
<view class="tn-subsection__item tn-text-ellipsis" :class="[
'section-item-' + index,
noBorderRight(index)
]"
:style="[itemStyle(index)]"
@tap="click(index)"
>
]" :style="[itemStyle(index)]" @tap="click(index)">
<view class="tn-subsection__item--text tn-text-ellipsis" :style="[textStyle(index)]">
{{ item.name }}
</view>
</view>
</block>
<!-- 背景 -->
<view
class="tn-subsection__bg"
:class="[itemBarClass]"
:style="[itemBarStyle]"
></view>
<view class="tn-subsection__bg" :class="[itemBarClass]" :style="[itemBarStyle]"></view>
</view>
</template>
@@ -123,6 +111,24 @@
}
},
watch: {
list: {
handler(val) {
this.listInfo = val.map((item, index) => {
if (typeof item !== 'object') {
let obj = {
width: 0,
name: item
}
return obj
} else {
item.width = 0
return obj
}
})
},
immediate: true,
deep: true
},
current: {
handler(val) {
this.currentIndex = val
@@ -337,7 +343,6 @@
</script>
<style lang="scss" scoped>
.tn-subsection {
/* #ifndef APP-PLUS */
display: flex;
@@ -406,5 +411,4 @@
}
}
}
</style>