js判断是否处于移动端
应用场景
在uniapp中通过webview嵌入了PC端界面,某些界面方法需要根据处于PC还是uniapp进行不同的处理,此处简单通过界面宽度去判断。
代码示例
const { body } = document const WIDTH = 992 isMobile() { const rect = body.getBoundingClientRect() return rect.width - 1 < WIDTH }
const { body } = document const WIDTH = 992 isMobile() { const rect = body.getBoundingClientRect() return rect.width - 1 < WIDTH }