The data flow of my app begins with a backend API request which launches a Vue component using puppeteer. Is there any way I can pass that data from Backend (express) to the vue component which is launched other than making the Vue component call a backend API to fetch data?
I have tried calling a backend API from the launched component but this seems to be a work-around rather than an actual solution.
Functions added to the
windowobject through puppeteer'sexposeFunctionmethod can be called from within a Vue component to retrieve data from the backend.For example, the puppeteer code (in an example where the backend API request contained the data
myData):And the code you would put in Vue, to be executed when the component is mounted:
Or if you need to get the types to compile in typescript:
Another way to pass information from puppeteer to vue.js is through custom events and event listeners
For example, using vue3's composition syntax, the js part of a vue SFC could look like:
I believe this correlates to the following in vue2, although I'm unable to test this at the moment:
On the puppeteer side of things, send the event using the evaluate method: