codecamp

Weex 事件

组件通用事件与 Weex 通用事件相同,Rax 中需要以 on 开头驼峰方式命名

<View onClick={() => {}}>
  ...
</View>

页面事件,需要通过 setNativeProps API 手动向 body 节点绑定

let bodyProps = {
  onViewAppear: () => {},
  onViewDisAppear: () => {}
};
let weexDocument = typeof __weex_document__ === 'object' ? __weex_document__ : typeof document === 'object' ? document : {};
if (weexDocument && weexDocument.body) {
  setNativeProps(findDOMNode(weexDocument.body), bodyProps);
}

事件冒泡

let bodyProps = {
  bubble: true,
};
let weexDocument = typeof __weex_document__ === 'object' ? __weex_document__ : typeof document === 'object' ? document : {};
if (weexDocument && weexDocument.body) {
  setNativeProps(findDOMNode(weexDocument.body), bodyProps);
}

阻止冒泡

<View onClick={(event) => {
	event.stopPropagation();
}}>
  ...
</View>


Weex 页面降级
Weex 事件通信
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定