[Vue warn]: Error in render: "TypeError: Cannot read property 'length' of null"

 错误原因的可能:

  1. 在data中只定义了form对象而没有完全设置相应的属性
  2. 获取到的数据中没有结果的字段值是Null

数据请求到的数据可以输出看到结果,但是渲染不到页面上,这时候要使用this.$set()强制赋值(之前学习这个方法的时候,以为会用不到,现在终于用上了)

 let username=JSON.parse(this.$store.state.userInfo).username
      this.username=username
      getUserInfo(username).then(res=>{
        this.$set(this.form,res.data.data)
      })

this.$set(target,key,value)

target:目标对象

key:具体要修改的数据

value:重新赋的数据

原文地址:https://www.cnblogs.com/shanchui/p/14361739.html