s***@163.com
s***@163.com
  • 发布:2022-10-05 10:45
  • 更新:2022-10-06 11:49
  • 阅读:204

【报Bug】for key="item.id" 不正常,key="index"则正常

分类:uni-app

产品分类: uniapp/小程序/微信

PC开发环境操作系统: Windows

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

HBuilderX类型: 正式

HBuilderX版本号: 3.6.4

第三方开发者工具版本号: 任何

基础库版本号: 任何

项目创建方式: HBuilderX

操作步骤:

点击添加,点击1

预期结果:

日志输出1

实际结果:

日志输出3

bug描述:

<template>  
    <view class="content">  
        <template v-for="item in list" :key="item.id">  
            <view class="item" @click="showid(item.id)">{{ item.id }}</view>  
        </template>  
  
        <view class="button" @click="add">添加</view>  
  
        <view>str:{{ str }}</view>  
    </view>  
</template>    
  
<script lang="ts">  
import {  
    ref,  
    computed,  
    reactive  
} from 'vue';  
export default {  
    setup() {  
        const str = ref("");  
        const obj = reactive({  
            list: [{  
                id: 1  
            }, {  
                id: 2  
            }]  
        });  
  
        const list = computed(() => obj.list);  
  
        const add = () => {  
            obj.list.unshift({  
                id: 3  
            });  
        };  
  
        const showid = (id: number) => {  
            str.value = id + "";  
        };  
  
        return {  
            add,  
            showid,  
            str,  
            list  
        }  
    }  
}    
</script>  
  
<style lang="scss">  
.item {  
    line-height: 100rpx;  
    padding: 0 20px;  
    background: #f00;  
    border-bottom: solid 2px #fff;  
    margin: 2px 0;  
}  
  
.button {  
    height: 100rpx;  
    line-height: 100rpx;  
}  
</style>
2022-10-05 10:45 负责人:无 分享
已邀请:
DCloud_UNI_WZF

DCloud_UNI_WZF

vue3 微信小程序数组 unshift 复现该问题,感谢反馈,已加分

  • s***@163.com (作者)

    splice也有这个问题,也处理一下吧


    2022-10-07 13:14

要回复问题请先登录注册