点击事件openClick打印item 显示为undefined
在HBuilderX4.45中也有这个问题
产品分类: uniapp/小程序/微信
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: Windows 11
HBuilderX类型: 正式
HBuilderX版本号: 4.36
第三方开发者工具版本号: 1.06.2409140
基础库版本号: 3.7.9
项目创建方式: HBuilderX
点击事件openClick打印item 显示为undefined
在HBuilderX4.45中也有这个问题
事件openClick打印item
点击事件openClick打印item 显示为undefined
<template>
<view class="page-min hospital-view column px-32">
<view class="u-bdr-16 bg-f w-100 space-between u-m-t-20 u-p-20" v-for="(item,index) in list" :key="item.id" @click="openClick(item)">
<u-image width="110rpx" height="110rpx" border-radius="10" :src="item.logo_img"></u-image>
<view class="u-flex-1 u-m-l-12">
<view class="u-f-30 font-weight-550">{{ item.shop_name }}</view>
<view class="u-m-t-12 u-flex">
<view class="u-flex-1 u-f-24 w-s-color-6">{{ item.address }}</view>
<view class="u-m-l-14 u-flex u-f-24 text-primary">
<image src="@/static/icon/19.png" class="address-img" mode=""></image>
<text>{{ item.distance_unit }}</text>
</view>
</view>
</view>
</view>
</view>
</template>
<script>
import api from '@/api/shop.js';
export default {
data() {
return {
/* 列表相关 */
loading: 'loading',
refreshFlag: true,
list: [],
total: 0,
query: {
page: 1,
latitude: '30.237885',
longitude: '120.209764',
city_id: ''
},
cityShow: false,
cityText: '杭州',
cityList: []
};
},
onShow() {
this.refresh();
},
onPullDownRefresh() {
this.refresh();
},
onReachBottom() {
if (this.loading == 'loadmore') {
this.query.page += 1;
this.getList();
}
},
methods: {
/* 打开地图 */
openClick(item) {
console.log(item);
return
uni.openLocation({
latitude: Number(item.latitude),
longitude: Number(item.longitude),
success: () => {},
fail: (err) => {
console.log(err);
}
});
},
/**
* 刷新
*/
refresh() {
this.refreshFlag = true;
this.query.page = 1;
uni.showLoading({
title: '加载中'
});
this.getList();
},
getList() {
this.loading = 'loading';
api.getHospitalList(this.query).then((res) => {
let { data, total } = res.data.list;
if (this.refreshFlag) {
this.list = data;
uni.hideLoading();
this.refreshFlag = false;
uni.stopPullDownRefresh();
} else {
this.list = [...this.list, ...data];
}
this.total = total;
this.loading = this.list.length < total ? 'loadmore' : 'nomore';
});
}
}
};
</script>
<style lang="scss" scoped>
.hospital-view {
padding-bottom: calc(20rpx + constant(safe-area-inset-bottom));
padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
.address-img {
width: 28rpx;
height: 28rpx;
margin-right: 4rpx;
}
.city-view {
padding: 34rpx 28rpx;
.city-scoll {
max-height: 540rpx;
.city-all {
overflow: hidden;
.city-tag {
padding: 0 28rpx 30rpx 0;
float: left;
width: 25%;
.tag-view {
padding: 16rpx 20rpx;
text-align: center;
border-radius: 16rpx;
border: 2rpx solid rgba(170, 170, 170, 0.38);
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
font-size: 24rpx;
transition: all 0.3s;
}
.active-tag {
border-color: #ef1b49;
color: #ef1b49;
}
}
}
}
}
}
</style>
事件openClick打印item 显示为undefined
在h5中正常
3 个回复
xyj199509 (作者)
改成openClick(index,item)
openClick(index,item) {
console.log(item);
console.log(index);
return
uni.openLocation({
latitude: Number(item.latitude),
longitude: Number(item.longitude),
success: () => {},
fail: (err) => {
console.log(err);
}
});
},
index能够拿到,item始终拿不到,整个项目就这一个页面出现了这个问题
DCloud_UNI_yuhe
hello , 我这里不能直接运行你的代码,因此无法直接复现,但是从你的代码中,可能的原因是绑定问题或者是盒子大小等因素,可以提供一下一个可以复现的项目吗?
xyj199509 (作者)
项目目前没上线
2025-03-07 16:25
亚瑟
回复 xyj199509: 可以新建一个hello项目,将代码copy过去,然后数据写死看看
2025-03-07 16:32
xyj199509 (作者)
你好,方便提供微信号吗!我给你拉到体验版
2025-03-07 16:32
xyj199509 (作者)
回复 亚瑟: 好的,我试试
2025-03-07 16:33
xyj199509 (作者)
回复 亚瑟: 能出来
2025-03-07 16:40
xyj199509 (作者)
写死数据后原来的项目也能出来,从后端请求数据后就出不来了
2025-03-07 16:43
xyj199509 (作者)