Vue Js Get Src from Iframe
Vue Js Get Src from Iframe:To get the "src" attribute value of an iframe in Vue.js, you can use the "ref" attribute to create a reference to the iframe element, and then access its "src" property in the component's methods or computed properties.
written
reviewed
updated
Thanks for your feedback!
Your contributions will help us to improve service.
How can I retrieve the src attribute value of an <iframe> element in Vue js?
This Vue.js code defines a component with an iframe and a button that, when clicked, updates the value of iframeSrc with the src attribute of the iframe. Here's how it works:
- The
datafunction defines an initial value foriframeSrcas an empty string. - The
getIframeSrcmethod is called when the button is clicked. It retrieves thesrcattribute of the iframe using therefproperty to get a reference to the iframe element. - The
iframeSrcproperty is updated with the retrievedsrcvalue, which causes Vue.js to update the DOM and display thepelement containing the iframe's source URL.
Note that this code is using the $refs property to get a reference to the iframe element. This is a Vue.js feature that allows components to access child components or DOM elements with a unique ref attribute.
Output of Vue Js Get Src from iframe

Ad