a***@foxmail.com
a***@foxmail.com
  • 发布:2022-12-07 16:42
  • 更新:2023-01-10 11:09
  • 阅读:397

【报Bug】vue3编译 动态绑定样式(动态设置边框有问题)

分类:uni-app

产品分类: uniapp/H5

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: win11

HBuilderX类型: 正式

HBuilderX版本号: 3.6.5

浏览器平台: Chrome

浏览器版本: 版本 108.0.5359.95(正式版本) (64 位)

项目创建方式: HBuilderX

示例代码:
<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-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;

如下图:

2022-12-07 16:42 负责人:无 分享
已邀请:
DCloud_UNI_Anne

DCloud_UNI_Anne

问题复现已记录后续优化 ,已加分感谢反馈!

YUANRJ

YUANRJ

给vue提交的 pr 已合并,待发版同步。可以先别使用简写属性临时解决。

YUANRJ

YUANRJ

是vue的问题,给组件样式添加简写属性时,样式更新有问题,已向vue反馈。

要回复问题请先登录注册