首页 > 解决方案 > 无法读取 vue.js 中的属性问题如何解决?

问题描述

我像道具一样传递它:['user'],

然后在数据对象中是这样吗

    form : {        
                id : this.user.id , 
                birthplace : this.user.profile.birthplace,

[Vue 警告]:data() 中的错误:“TypeError:无法读取 null 的属性‘出生地’”

---> 在 resources/assets/js/components/EditCriminal.vue 警告 @ app.js:80633 app.js:81896 TypeError: Cannot read property 'birthplace' of null

标签: laravelvue.js

解决方案


最好将 的值传递propdata这样的项目:

data(){
     return{
          form{
               id:null,
               birthplace:null
          }
     }
},
props:['user'],
created(){
     if(this.user){
          this.form.id = this.user.id;
          if(this.user.profile)
               this.form.birthplace = this.user.profile.birthplace,
     }
}

推荐阅读