修复分段器动态赋值不生效的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> <template>
<view <view class="tn-subsection-class tn-subsection" :class="[subsectionBackgroundColorClass]"
class="tn-subsection-class tn-subsection" :style="[subsectionStyle]">
:class="[subsectionBackgroundColorClass]"
:style="[subsectionStyle]"
>
<!-- 滑块 --> <!-- 滑块 -->
<block v-for="(item, index) in listInfo" :key="index"> <block v-for="(item, index) in listInfo" :key="index">
<view <view class="tn-subsection__item tn-text-ellipsis" :class="[
class="tn-subsection__item tn-text-ellipsis"
:class="[
'section-item-' + index, 'section-item-' + index,
noBorderRight(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)]"> <view class="tn-subsection__item--text tn-text-ellipsis" :style="[textStyle(index)]">
{{ item.name }} {{ item.name }}
</view> </view>
</view> </view>
</block> </block>
<!-- 背景 --> <!-- 背景 -->
<view <view class="tn-subsection__bg" :class="[itemBarClass]" :style="[itemBarStyle]"></view>
class="tn-subsection__bg"
:class="[itemBarClass]"
:style="[itemBarStyle]"
></view>
</view> </view>
</template> </template>
@@ -49,7 +37,7 @@
// tab的数据 // tab的数据
list: { list: {
type: Array, type: Array,
default() { default () {
return [] return []
} }
}, },
@@ -123,6 +111,24 @@
} }
}, },
watch: { 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: { current: {
handler(val) { handler(val) {
this.currentIndex = val this.currentIndex = val
@@ -337,7 +343,6 @@
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.tn-subsection { .tn-subsection {
/* #ifndef APP-PLUS */ /* #ifndef APP-PLUS */
display: flex; display: flex;
@@ -406,5 +411,4 @@
} }
} }
} }
</style> </style>