NervJS / taro

开放式跨端跨框架解决方案,支持使用 React/Vue/Nerv 等框架来开发微信/京东/百度/支付宝/字节跳动/ QQ 小程序/H5/React Native 等应用。 https://taro.zone/
https://docs.taro.zone/
Other
35.46k stars 4.78k forks source link

#Taro 代码与微信小程序代码混写# 怎么向微信小程序的 template组件传入 bindtap 方法呢? #2374

Closed harrydengchao closed 5 years ago

harrydengchao commented 5 years ago

问题描述

Taro 代码与微信小程序代码混写# 怎么向微信小程序的 template组件传入 bindtap 方法呢?

复现步骤

<!-- a.wxml -->
<template name="a">
    <button bindtap="handleInput">测试</button>
</template>
// Taro component
<View>
    <import src="xx/xx/a.wxml" />
    <template is="a" />
</View>

期望行为 在 Taro 中向 微信小程序 template 传入 handleInput 方法,使得 a.wxml 中的 bindtap 事件可以正确响应

报错信息

Component "pages/index/index" does not have a method "handleInput" to handle event "tap". image

系统信息

Taro v1.2 及以上版本已添加 taro info 命令,方便大家查看系统及依赖信息,运行该命令后将结果贴下面即可。

补充信息 [可选] [根据你的调查研究,出现这个问题的原因可能在哪里?]

taro-bot[bot] commented 5 years ago

欢迎提交 Issue~

如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏

如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。

Good luck and happy coding~

harrydengchao commented 5 years ago

个人感觉,这问题目前无解。因此自己改为了,用到这个场景的页面,用微信小程序写。没有用到这个场景的部分,用 Taro 写。

luckyadam commented 5 years ago

目前确实无解

harrydengchao commented 5 years ago

感谢您的回复

febobo commented 5 years ago

在你的Taro component页面加一个<view style={{display: none}} onClick={你要添加的方法}/> 目的是让你的方法被编绎

harrydengchao commented 5 years ago

@febobo 感谢你的回复。 如上你的方案,我理解的是,只能在 Taro component 中编译方法。 无法解决向 Taro component 中引用的 wechat template 传递方法的问题。 不知道我理解的正确否?

febobo commented 5 years ago

@harrydengchao 你就当成数据传过去, 参考 wxparse事件处理