首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从模板组件中收听react/角/vue中的事件

如何从模板组件中收听react/角/vue中的事件
EN

Stack Overflow用户
提问于 2020-09-08 06:50:11
回答 1查看 402关注 0票数 0

我已经在stencils.js中创建了一个简单的组件,并在react/角/vue中使用了这个组件。在我的模具组件中,我发出了一个事件。此事件在角/react/vue中捕获。我的问题是,我需要在一个html中使用同一组件两次。如何识别哪个事件是由哪个组件实例发出的?

EN

回答 1

Stack Overflow用户

发布于 2022-06-20 14:20:51

使用@stencil/react-output-target库并遵循本指南,您将能够这样做:

代码语言:javascript
复制
//button component
import { Component, Prop, h } from '@stencil/core';

@Component({
  tag: 'button-component',
  styleUrl: 'button.css',
  shadow: false,
  scoped: true
})
export class MyComponent {
  @Prop() label: string;

  render() {
    return <button type="button">{this.label}</button>;
  }
}

// button component instance in React
<ButtonComponent label='Test Button' onClick={() => alert("Hi, I'm a button alert!")}/>

在几个小时试图在模具组件内部传递一个函数之后才发现的.

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63788507

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档