利用动态:class来判断字长调整选项卡uni-data-select 宽度
//html
<view>
<view
style="width:100%"
:class="checkLength(text)>4 ? 'textexplode':''textshrink">
<uni-data-select
v-model="value"
:localdata="rangeTag"
@change="changeStyleTag"
:clear="false">
</uni-data-select>
</view>
</view>
//data
// Tag选项卡
value: 0, // 默认index当前索引
rangeTag: [
{ value: 0, text: "xxxxxxx" },
{ value: 1, text: "xxx" },
],
text: '',
// 首次加载页面
onLoad () {
this.rangeTag.map(v => {
if (this.value == v.value) {
this.text = v.text
}
})
},
methods: {
// 选项卡点击事件
changeStyleTag (e) {
//console.log('changeStyleTag', e)
this.rangeTag.map(v => {
if (e == v.value) {
this.text = v.text
}
})
//conso

文章介绍了如何使用Vue中的动态class来根据字符串长度调整uni-data-select组件的宽度,以及避免在v-if/else分支中使用相同key的注意事项。
最低0.47元/天 解锁文章
2291

被折叠的 条评论
为什么被折叠?



