zoukankan      html  css  js  c++  java
  • uniapp报错记录:Unexpected end of JSON input、

    1、Unexpected end of JSON input原因及如何解决

      总是遇到一个报错,导致有时候渲染有问题,我们看看啥报错:

    11:29:07.092 [Vue warn]: Error in render: "SyntaxError: Unexpected end of JSON input"
    11:29:07.131 (found at pages/account/account.vue:1)
    11:29:07.152 SyntaxError: Unexpected end of JSON input

      初看是JSON解析的问题。但是account代码很简单,没什么json解析问题啊,后来发现是取userInfo信息时报错

      getters: {
        userInfo(state) {
          if (!state.userInfo) {
            state.userInfo = JSON.parse(uni.getStorageSync('userInfo'))
          }
          return state.userInfo
        }
      },

      如果userInfo不存在时,去storage里面取,如果不存在,这时候就为空。JSON.parse(''),所以就报这个错。

    JSON.parse('')
    // VM483:1 Uncaught SyntaxError: Unexpected end of JSON input
    //    at Object.parse (<anonymous>)
    //    at <anonymous>:1:6

      那么知道了原因,稍微改一下即可:

      getters: {
        userInfo(state) {
          if (!state.userInfo) {
          let _user = uni.getStorageSync('userInfo')
          state.userInfo = _user ? JSON.parse(_user) : null
          }
          return state.userInfo
        }
      },
  • 相关阅读:
    sgg_3_hibernate详解
    sgg_2_hibernate开发步骤
    sgg_1_hibernate概述
    cookie
    exchange 普通用户可以创建通讯组
    DC 维护常用工具命令DCdiag
    cp 复制不覆盖
    powershell 结果输出显示为……
    获得用户完整的autodiscover配置文件
    【转】outlook 2016 配置自动发现
  • 原文地址:https://www.cnblogs.com/goloving/p/14205675.html
Copyright © 2011-2022 走看看