点击添加,点击1

- 发布:2022-10-05 10:45
- 更新:2022-10-06 11:49
- 阅读:299
产品分类: uniapp/小程序/微信
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: windows 11
HBuilderX类型: 正式
HBuilderX版本号: 3.6.4
第三方开发者工具版本号: 任何
基础库版本号: 任何
项目创建方式: HBuilderX
操作步骤:
预期结果:
日志输出1
日志输出1
实际结果:
日志输出3
日志输出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>
s***@163.com (作者)
splice也有这个问题,也处理一下吧
2022-10-07 13:14