<template>
<view class="test">
<block v-for="(item, index) in 5" :key="index">
<view :style="index==cureentIndex?'border: 2px solid red':'border-bottom: 2px solid black;'">测试</view>
</block>
<button type="primary" @tap="changeIndex">切换</button>
</view>
</template>
<script>
export default {
data() {
return {
cureentIndex: 0
};
},
onLoad() {},
methods: {
changeIndex() {
if (this.cureentIndex < 4) ++this.cureentIndex;
else this.cureentIndex = 0;
}
}
};
</script>
<style lang="less">
.test{
padding: 30rpx;
&>view{
padding: 10rpx;
text-align: center;
margin-bottom: 20rpx;
}
}
</style>
- 发布:2022-12-07 16:42
- 更新:2023-01-10 11:09
- 阅读:592
产品分类: uniapp/H5
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: win11
HBuilderX类型: 正式
HBuilderX版本号: 3.6.5
浏览器平台: Chrome
浏览器版本: 版本 108.0.5359.95(正式版本) (64 位)
项目创建方式: HBuilderX
示例代码:
操作步骤:
在HBuilder X 里 vue3编译如下代码,在任意浏览器中打开后点击切换按钮
<template>
<view class="test">
<block v-for="(item, index) in 5" :key="index">
<view :style="index==cureentIndex?'border: 2px solid red':'border-bottom: 2px solid black;'">测试</view>
</block>
<button type="primary" @tap="changeIndex">切换</button>
</view>
</template>
<script>
export default {
data() {
return {
cureentIndex: 0
};
},
onLoad() {},
methods: {
changeIndex() {
if (this.cureentIndex < 4) ++this.cureentIndex;
else this.cureentIndex = 0;
}
}
};
</script>
<style lang="less">
.test{
padding: 30rpx;
&>view{
padding: 10rpx;
text-align: center;
margin-bottom: 20rpx;
}
}
</style>
在HBuilder X 里 vue3编译如下代码,在任意浏览器中打开后点击切换按钮
<template>
<view class="test">
<block v-for="(item, index) in 5" :key="index">
<view :style="index==cureentIndex?'border: 2px solid red':'border-bottom: 2px solid black;'">测试</view>
</block>
<button type="primary" @tap="changeIndex">切换</button>
</view>
</template>
<script>
export default {
data() {
return {
cureentIndex: 0
};
},
onLoad() {},
methods: {
changeIndex() {
if (this.cureentIndex < 4) ++this.cureentIndex;
else this.cureentIndex = 0;
}
}
};
</script>
<style lang="less">
.test{
padding: 30rpx;
&>view{
padding: 10rpx;
text-align: center;
margin-bottom: 20rpx;
}
}
</style>
预期结果:
正常应该是border:red
正常应该是border:red
实际结果:
结果是:
border-top: 2px solid red;
border-right: 2px solid red;
border-left: 2px solid red;
border-image: initial;
结果是:
border-top: 2px solid red;
border-right: 2px solid red;
border-left: 2px solid red;
border-image: initial;
bug描述:
动态设置边框样式在vue2中正常,vue3中【编译器】会将border 编译为 :
border-top: 2px solid red;
border-right: 2px solid red;
border-left: 2px solid red;
border-image: initial;
如下图: