javascript - 如何让 iframe 在后台保持活跃?

标签 javascript vue.js iframe vue-router

我有一个带有 2 个 iframe 的简单 Vue.js 应用程序。

使用 Vue 路由器我想在两个 iframe 之间切换,但我想让 iframe 在后台保持“事件”,因此不需要每次都重新加载 iframe。

知道为什么下面的 fiddle 不起作用吗? (请注意,每次来回切换时它都会重新加载 iframe)

http://jsfiddle.net/c3umtepz/1/

<div id="app">
  <router-link to="/">/youtube.com</router-link>
  <router-link to="/foo">/adobe.com</router-link>
  <keep-alive>
    <router-view></router-view>
  </keep-alive>
</div>

最佳答案

Keep-alive 在这里不起作用,您的解决方案 v-show是正确的

The keep-alive principle is to keep the node information in the component in VNode (in memory) and render from VNode to real DOM when rendering is needed. The content in the iframe page does not belong to the information of the node, so using keep-alive will still re-render the content in the iframe

关于javascript - 如何让 iframe 在后台保持活跃?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45662534/

相关文章:

javascript - 我可以将函数绑定(bind)到父窗口的onscroll事件吗?

css - 响应式 iframe,全宽,但设置高度

javascript - JS : check if setTimeout has finished or been canceled

Javascript 函数没有按其应有的方式更改 html 文档的名称属性

javascript - 从客户端获取服务器日期时间

JavaScript 作用域问题

vue.js - Laravel +Vue,如何在vue中获取url参数

javascript - v-for 列表中的 Vue2 模态

javascript - 无法在另一个 javascript 文件中调用 javascript 函数

javascript - 问题: Javascript iframe send the postMessage() before iframe completed loading