Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在megalo(Vue)中,如何绑定事件 #2

Open
hiNISAL opened this issue Feb 13, 2019 · 2 comments
Open

在megalo(Vue)中,如何绑定事件 #2

hiNISAL opened this issue Feb 13, 2019 · 2 comments

Comments

@hiNISAL
Copy link

hiNISAL commented Feb 13, 2019

您好😊
仓库的例子中提供了几种小程序里绑定事件的方式

尝试着在megalo中使用的时候无法绑定事件

请问有例子可以参考吗 或者有没有相关的文档供翻阅

谢谢

@elcarim5efil
Copy link
Member

�目前还没有提供这样的接口,已经把需求列入需求池

@hiNISAL
Copy link
Author

hiNISAL commented Feb 19, 2019

我尝试着使用mountAction方法,但是好像没起作用。我理解的是这个是用来设定事件规则的。

通过翻阅源码看到mountAction似乎相对独立,只经过了一层导入和导出,没有在编译过程中绑定事件,只是根据传入的规则做了一层处理后,将一个函数挂到传入的第一个参数中。

因为是粗略的阅读,所以猜测这个方法可能是作为事件进行绑定的,我也尝试着使用,比如直接作为事件代理给最外层,或者将事件对象传递给agentFunc,但是好像没有啥特殊的反应,调用和不调用的效果差不多。

请问这个方法有相关的内容文档供参考吗😄如果可以,那可以在megalo中使用小程序组件,代替v-html


我是想给a标签绑定上事件(业务奇特😂),通过冒泡的方式抓不到,后来发现是因为转换后的表现是这样的

// <a href="https://baidu.com">百度</a>

<viewclass="octoParse-div"data-class=""data-id="undefined"data-tag="div"style=""role=""aria-label="">
  <viewclass="octoParse-inline octoParse-a"data-class=""data-id="undefined"data-src="https://baidu.com"data-tag="a"style=""role=""aria-label="">
    <viewclass="WxTextView octoParse-inline"style="undefined"role=""aria-label=""> 百度 </view>
  </view>
</view>

似乎是因为这一层WxTextView octoParse-inline撑起了上层的关系,导致tap的时候的target为这一层,而这一层中没有任何有用的数据。然后我在微信的模版中将

<template name="WxTextView">
    <view class="WxTextView octoParse-inline" style="{{item.styleStr}}">
      {{item.text}}
    </view>
</template>

修改成

<template name="WxTextView">
      {{item.text}}
</template>

target就成了上层,可以拿到data-*属性。

暂时可以这样解决。


三更..

目前通过上面那种修改模版的方式,已经解决想拿到a标签数据的问题。

<div @click="tap">
    <div v-html="vhtml" />
</div>

使用这种代理方式,拿到了想要的数据。

谢谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants