Reputation: 477
Can I change the value of an input to the src of an iframe. Is this possible with VueJS I am picturing:
<input id="input"/>
<iframe src="welcome.html"></iframe>
let vm = new Vue ({
data: {
src: "welcome.html",
},
});
document.getElementById("input").value = /* src from vm.data? */
Upvotes: 2
Views: 12360
Reputation: 836
Vue.component('base-iframe', {
data: function() {
return {
url: 'https://example.com'
}
},
template: '<iframe :src="url" />'
})
new Vue({
el: '#components-demo'
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.10/vue.min.js"></script>
<div id="components-demo">
<base-iframe />
</div>
Upvotes: 1
Reputation: 3614
You should be able to do something like:
<input id="input"/>
<iframe :src="iframeSrc"></iframe>
let vm = new Vue ({
data: {
iframeSrc: "welcome.html",
},
});
But you need to bind Vue to some parent element, like <div id="app"></div>
new Vue({
el: "#app",
...
}
Upvotes: 5