vconsole在低版本浏览器上白屏问题(包括ios Android)Vue解决方案

内容分享2小时前发布
0 1 0

vconsole是一个在移动设备上调试的神器,但是在某些手机上,会有白屏问题。
先看报错:

Uncaught ReferenceError: ResizeObserver is not defined,source: http://10.1.2.113:8081/js/app.js(4422)

这段报错指出ResizeObserver 这个方法找不到
百度找了一下这个API

vconsole在低版本浏览器上白屏问题(包括ios Android)Vue解决方案

这个api是用来vconsole界面大小适配用的

vconsole在低版本浏览器上白屏问题(包括ios Android)Vue解决方案

这个api的兼容性实则已经算很好了,但耐不住公司有特别古老的机型在测试,最低版本的安卓也是2018年月更新的适配。

为了解决这个适配问题

  1. 安装resize-observer-polyfill

yarn  add resize-observer-polyfill
或者
npm i resize-observer-polyfill

2.main.js引入

import ResizeObserver from  resize-observer-polyfill 
挂载到window上,由于插件内是使用的new语法 会直接在window上找
 window.ResizeObserver = ResizeObserver

至此,问题解决..

© 版权声明

相关文章

1 条评论

  • 头像
    中医田应旭 投稿者

    牛的 帮大忙了

    无记录
    回复