uni-app icon indicating copy to clipboard operation
uni-app copied to clipboard

for循环中,同一个标签绑定多个事件的时候, 获取不到事件传参

Open adams549659584 opened this issue 7 years ago • 2 comments

问题描述 [问题描述:尽可能简洁清晰地把问题描述清楚] for循环中,同一个标签绑定多个事件的时候, 获取不到事件传参 复现步骤

<template>
  <div class="content">
    <div>
      <div v-for="(sku,index) in wareSkus" :key="index">
        <button @click="testClick(sku);testClick2(sku);" >测试点击{{sku.code}}</button>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { Vue, Component } from 'vue-property-decorator';

@Component({
  components: {}
})
export default class Index extends Vue {
  wareSkus = [{ code: '111', name: 'aaaaaa' }, { code: '222', name: 'bbbbbb' }, { code: '333', name: 'cccccc' }];

  testClick(e: any) {
    debugger;
  }
  testClick2(sku: any) {
    debugger;
  }
}
</script>

[复现问题的步骤]

  1. 启动 '...'
  2. 点击 '....'
  3. 查看

[或者可以直接贴源代码]

预期结果 [使用简洁清晰的语言描述你希望生效的预期结果] 可以正确获取循环中的传参 实际结果 [这里请贴上你的报错截图或文字] [Vue warn]: Property or method "sku" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property.

系统信息:

  • 发行平台: [如 微信小程序、H5平台、5+ App等]
  • 操作系统 [如 iOS 12.1.2、Android 7.0]
  • HBuilderX版本 [如使用HBuilderX,则需提供 HBuilderX 版本号]
  • uni-app版本 [如使用Vue-cli创建/运行项目,则提供npm run info的运行结果]
  • 设备信息 [如 iPhone8 Plus]

补充信息 [可选] [根据你的分析,出现这个问题的原因可能在哪里?] 表达式转译可能有问题,for循环中的多事件绑定的没处理 图一为uniapp的,图二是原生vue的 uniapp 原生vue

adams549659584 avatar Aug 25 '19 06:08 adams549659584

写到同一个函数里面不就行了,为什么要传两个函数到click里面

jwhklk avatar Aug 26 '19 09:08 jwhklk

旧的mpvue项目想迁移过来,里面很多事件这样写了,特别是一些跟踪事件,写了很多

adams549659584 avatar Aug 26 '19 09:08 adams549659584