首页 > 技术文章 > vue 在pc端调试正常执行,移动端失败 ,页面空白

bigsister 2019-05-09 15:16 原文

移动端对代码的执行较为严格,语句出现undefined或其他时,不报错的同时页面空白或在created中获取不到data的值,并且不能改变data的属性

例如:

  给memberId 赋值时,从缓存中获取id,若缓存中的userInfo为null,移动端不报错,同时不执行,不能更改其值以及data中的其他属性的值,导致页面异常

        memberId: JSON.parse(getStore("userInfo")).id,

解决方案,对获取值进行可能存在的异常兼容处理

memberId: getStore("userInfo")!=null && getStore("userInfo") != "" ? JSON.parse(getStore("userInfo")).id : 9999999,

 

推荐阅读