Hope you are doing well!
I am working on a vue 3 application which has n number of components. One of the component has a js file inside which there is a js function which is called.
This js function is in external javascript file and it returns a data.
Now how can i catch this data in my vue component?
2
Answers
You should export the function in the external javascript file and then import it in your vue component. Then you can call it and get the data. Here is an example:
Your external javascript file:
And in your vue component:
Assuming you have an external JavaScript file named external.js with a
getData()
function that returns data:In your Vue component, you can import this external file and use the getData() function:
getData()
is imported from theexternal.js
file.myData
is a Vue ref that will store the data returned by the external function.The
onMounted
function is used to ensure that the call togetData()
occurs after the component has been mounted.Make sure to adjust the path to the external file based on your project structure.