direflow icon indicating copy to clipboard operation
direflow copied to clipboard

How to provide component instance methods for external use

Open crazyming9528 opened this issue 3 years ago • 6 comments

I would like to know how to provide component instance methods for external use, thank you

crazyming9528 avatar Oct 12 '22 18:10 crazyming9528

There is two-way communication between host and web component via web component's properties and events. If this doesn't answer your question, please elaborate more what you want to achieve.

PrimaMateria avatar Oct 13 '22 18:10 PrimaMateria

There is two-way communication between host and web component via web component's properties and events. If this doesn't answer your question, please elaborate more what you want to achieve.

Just like the useImperativeHandle hook in react, can expose the methods of components.

eg.

class MyElement extends HTMLElement {
  ...
 
  doSomething() {
    // do something in this method
  }

const element = document.querySelector('my-element');
element.doSomething();

crazyming9528 avatar Oct 14 '22 08:10 crazyming9528

@PrimaMateria Can you help me solve this problem, it is very urgent, thank you very much

crazyming9528 avatar Oct 17 '22 18:10 crazyming9528

I don't have any knowledge about that, so I am not able to help you.

PrimaMateria avatar Oct 18 '22 09:10 PrimaMateria

I don't have any knowledge about that, so I am not able to help you.

ok,thanks for your reply~

crazyming9528 avatar Oct 18 '22 16:10 crazyming9528

I use custom event to call a method inside the component

crazyming9528 avatar Nov 01 '22 18:11 crazyming9528