将IFrame SRC绑定到VueJS数据

问题描述 投票:0回答:2

是否可以将input的值更改为iframesrc。 VueJS有可能吗我正在拍照:

<input id="input"/>
<iframe src="welcome.html"></iframe>

let vm = new Vue ({
  data: {
    src: "welcome.html",
  }, 
});
document.getElementById("input").value = /* src from vm.data? */
javascript html vue.js iframe input
2个回答
0
投票

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.5.17/vue.js"></script>
<div id="components-demo">
  <base-iframe />
</div>

0
投票

您应该可以执行以下操作:

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

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

但是您需要将Vue绑定到某些父元素,例如<div id="app"></div>

new Vue({
    el: "#app",
    ...
}
© www.soinside.com 2019 - 2024. All rights reserved.