vconsole是一個(gè)在移動(dòng)設(shè)備上調(diào)試的神器,但是在某些手機(jī)上,會(huì)有白屏問(wèn)題。
先看報(bào)錯(cuò):
Uncaught ReferenceError: ResizeObserver is not defined,source: http://10.1.2.113:8081/js/app.js(4422)
這段報(bào)錯(cuò)指出ResizeObserver 這個(gè)方法找不到
百度找了一下這個(gè)API

image.png
這個(gè)api是用來(lái)vconsole界面大小適配用的

image.png
這個(gè)api的兼容性其實(shí)已經(jīng)算很好了,但耐不住公司有特別古老的機(jī)型在測(cè)試,最低版本的安卓也是2018年月更新的適配。
為了解決這個(gè)適配問(wèn)題
- 安裝resize-observer-polyfill
yarn add resize-observer-polyfill
或者
npm i resize-observer-polyfill
2.main.js引入
import ResizeObserver from 'resize-observer-polyfill'
掛載到window上,因?yàn)椴寮?nèi)是使用的new語(yǔ)法 會(huì)直接在window上找
window.ResizeObserver = ResizeObserver
至此,問(wèn)題解決..