小葛
小葛
  • 发布:2024-02-04 14:52
  • 更新:2024-02-04 14:52
  • 阅读:296

【报Bug】uniapp x在template中调用methods中的函数,传入的数组中包含对象时,对象中属性丢失

分类:uni-app x

产品分类: uni-app x/App

PC开发环境操作系统: Windows

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

HBuilderX版本号: 4.01

手机系统: Android

手机系统版本号: Android 9.0

手机厂商: 模拟器

手机机型: 雷电模拟器

示例代码:

<template>
<uni-shadow-root class="vant-weapp-button-index">
<button ref="van-button" :class="getClass('button', [type, size, { plain, round }])" :type="type">
<text v-if="text">{{text}}</text>
<slot v-else></slot>
</button>
</uni-shadow-root>
</template>

<script lang="uts">
export default {
name: "van-button",
props: {
text: {
type: String,
default: ''
},
type: {
type: String,
default: 'default'
},
size: {
type: String,
default: 'normal'
},
plain: {
type: Boolean,
default: false
},
round: {
type: Boolean,
default: true
}
},
methods: {
getClass(name : string, conf : any[]) : string {
console.log(JSON.stringify(conf))
return name + JSON.stringify(conf)
},
}
}
</script>

操作步骤:

在template中调用methods中的getClass函数

预期结果:

拿到传入的所有值

实际结果:

数组中的对象属性丢失

bug描述:

函数getClass包含两个参数,第一个参数为string类型,第二个为any[],可以为['a', {b:1},['c']],在getClass中打印时发现,对象中的属性丢失

<template>  
    <uni-shadow-root class="vant-weapp-button-index">  
        <button ref="van-button" :class="getClass('button', [type, size, { plain, round }])" :type="type">  
            <text v-if="text">{{text}}</text>  
            <slot v-else></slot>  
        </button>  
    </uni-shadow-root>  
</template>  

<script lang="uts">  
    export default {  
        name: "van-button",  
        props: {  
            text: {  
                type: String,  
                default: ''  
            },  
            type: {  
                type: String,  
                default: 'default'  
            },  
            size: {  
                type: String,  
                default: 'normal'  
            },  
            plain: {  
                type: Boolean,  
                default: false  
            },  
            round: {  
                type: Boolean,  
                default: true  
            }  
        },  
        methods: {  
            getClass(name : string, conf : any[]) : string {  
                console.log(JSON.stringify(conf))  
                return name + JSON.stringify(conf)  
            },  
        }  
    }  
</script>
2024-02-04 14:52 负责人:无 分享
已邀请:

要回复问题请先登录注册