tapOption(e) {
console.log(e)
// #ifdef APP-NVUE
var index = e.currentTarget.attr.dataIndex
// #endif
// #ifndef APP-NVUE
var index = e.currentTarget.dataset.index
// #endif
this.$emit('tapindex', {detail: {index: index}})
}
- 发布:2024-11-18 12:04
- 更新:59 分钟前
- 阅读:21
产品分类: uniapp/App
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: window 10
HBuilderX类型: 正式
HBuilderX版本号: 4.29
手机系统: iOS
手机系统版本号: iOS 14
手机厂商: 苹果
手机机型: iphone 6s
页面类型: nvue
vue版本: vue2
打包方式: 云端
项目创建方式: HBuilderX
示例代码:
操作步骤:
点击列表下的某一栏
点击列表下的某一栏
预期结果:
console.log(e)
输出的是结构一个是:
{
"type": "click",
"timeStamp": 1731902250741,
"target": {
"id": "",
"attr": {
"dataIndex": 2
},
"offsetLeft": 0,
"offsetTop": 0
},
"currentTarget": {
"id": "",
"attr": {
"dataIndex": 2
},
"offsetLeft": 0,
"offsetTop": 0
},
"detail": {},
"stopPropagation": "function() { [native code] }"
}
console.log(e)
输出的是结构一个是:
{
"type": "click",
"timeStamp": 1731902250741,
"target": {
"id": "",
"attr": {
"dataIndex": 2
},
"offsetLeft": 0,
"offsetTop": 0
},
"currentTarget": {
"id": "",
"attr": {
"dataIndex": 2
},
"offsetLeft": 0,
"offsetTop": 0
},
"detail": {},
"stopPropagation": "function() { [native code] }"
}
实际结果:
console.log(e)
输出的是结构一个是:
{
"type": "click",
"timeStamp": 1731902250741,
"target": {
"id": "",
"dataset": {
"index": 2
},
"offsetLeft": 0,
"offsetTop": 0
},
"currentTarget": {
"id": "",
"dataset": {
"index": 2
},
"offsetLeft": 0,
"offsetTop": 0
},
"detail": {},
"stopPropagation": "function() { [native code] }"
}
而且走的位置是:
// #ifdef APP-NVUE
var index = e.currentTarget.attr.dataIndex
// #endif
console.log(e)
输出的是结构一个是:
{
"type": "click",
"timeStamp": 1731902250741,
"target": {
"id": "",
"dataset": {
"index": 2
},
"offsetLeft": 0,
"offsetTop": 0
},
"currentTarget": {
"id": "",
"dataset": {
"index": 2
},
"offsetLeft": 0,
"offsetTop": 0
},
"detail": {},
"stopPropagation": "function() { [native code] }"
}
而且走的位置是:
// #ifdef APP-NVUE
var index = e.currentTarget.attr.dataIndex
// #endif
bug描述:
index.nvue 引用了一个 子组件:report-box.vue,在子组件的列表下每栏都有点击事件:@tap="tapOption" :data-index="index"
8***@qq.com - 欢迎观看最近更新的《uni-app 踩坑实录》,涉及一些在文档上不容易看到的疑难杂症的解决方案。https://www.bilibili.com/cheese/play/ss60198
看你的代码:@tap="tapOption" :data-index="index", 调用子组件的地方,是能拿到index的。如果是想父组件获取点击的子组件的index的话,这样写:
父组件中:
<reportBox @click="showIndex(index)" />
7***@qq.com (作者)
你这个是整块子组件的点击事件,我这个是子组件下的 某个栏目的点击事件
子组件:
<view>
<view v-for="(item,index) in list" :key="index">
<view @tap="tapOption" :data-index="index">{{ item }}</view>
</view>
</view>
<scrpit>
export default {
methods: {
tapOption(e) {
/*
{
"type": "click",
"timeStamp": 1731902250741,
"target": {
"id": "",
"attr": {
"dataIndex": 2
},
"offsetLeft": 0,
"offsetTop": 0
},
"currentTarget": {
"id": "",
"attr": {
"dataIndex": 2
},
"offsetLeft": 0,
"offsetTop": 0
},
"detail": {},
"stopPropagation": "function() { [native code] }"
}
/
console.log(e)
// #ifdef APP-NVUE
// 执行了这步
var index = e.currentTarget.attr.dataIndex
// #endif
}
}
}
</script>
49 分钟前
7***@qq.com (作者)
是能解决,但它就是一个bug
46 分钟前