[FE] 被动检测 iframe 加载 src 成功失败的一种思路和方式 (Vue)

通过llama.cpp与羊驼聊天的网页界面- 详解 Serge 的启动使用

 

思路:设置定时器一个,n 秒后设置 404 或其它,此时给 iframe 的 onload 事件设置回调函数,加载完成则取消定时器。

 

示例:

data () {
  return {
    handler: null
  }
}

created () {
    this.handler = setTimeout(() => {
      const iframe = document.querySelector('#iframe_id')
      iframe.src = './404'
    }, 3000)
}

mounted () {
    const self = this
    const iframe = document.querySelector('#iframe_id')

    iframe.onload = function () {
      self.iframeCompleteLoad = true

      clearTimeout(self.handler)
    }
}

 

Link:https://www.cnblogs.com/farwish/p/14407369.html

posted on 2021-02-16 20:01  ercom  阅读(1575)  评论(0编辑  收藏  举报