最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Bind IFrame SRC to VueJS Data - Stack Overflow

programmeradmin3浏览0评论

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="wele.html"></iframe>

let vm = new Vue ({
  data: {
    src: "wele.html",
  }, 
});
document.getElementById("input").value = /* src from vm.data? */

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="wele.html"></iframe>

let vm = new Vue ({
  data: {
    src: "wele.html",
  }, 
});
document.getElementById("input").value = /* src from vm.data? */
Share Improve this question asked Jan 7, 2020 at 19:18 VisalVisal 4771 gold badge5 silver badges10 bronze badges 1
  • You should probably use Vue's ref to access the element – user9161752 Commented Jan 7, 2020 at 20:20
Add a ment  | 

2 Answers 2

Reset to default 5

You should be able to do something like:

<input id="input"/>
<iframe :src="iframeSrc"></iframe>

let vm = new Vue ({
  data: {
    iframeSrc: "wele.html",
  }, 
});

But you need to bind Vue to some parent element, like <div id="app"></div>

new Vue({
    el: "#app",
    ...
}

Vue.ponent('base-iframe', {
  data: function() {
    return {
      url: 'https://example.'
    }
  },
  template: '<iframe :src="url" />'
})

new Vue({
  el: '#ponents-demo'
})
<script src="https://cdnjs.cloudflare./ajax/libs/vue/2.6.10/vue.min.js"></script>
<div id="ponents-demo">
  <base-iframe />
</div>

发布评论

评论列表(0)

  1. 暂无评论