Vue 警告我无法在未定义、空值或原始值上设置反应性属性:空值

Adi*_*ya 6 javascript firebase vue.js vuetify.js

当读取数据从Firebase我尝试设置properties了中object获得的UI,但是当我尝试设置任何更改的数据,它将引发我这个错误。
v-on 处理程序中的错误:“类型错误:无法使用‘in’运算符在空值中搜索‘cc’。

我在开发模式下使用 Vue 以及Firebase. 有什么我遗漏的概念吗?

beforeCreate(){
sref.get().then(sc => {
      if (sc.exists) {
        console.log(sc.data()); //this logs in the correct data
        this.school = sc.data(); //this too
        this.cc = sc.data().cc;  //also this
        this.name = sc.data().name;
Run Code Online (Sandbox Code Playgroud)

当我做

console.log(this.name)
Run Code Online (Sandbox Code Playgroud)

created()它显示未定义时,任何更改或更新的尝试也会出错

Vue warn]: Cannot set reactive property on undefined, null, or primitive value: null
[Vue warn]: Error in v-on handler: "TypeError: Cannot use 'in' operator to search for 'cc' in null"

found in

---> <VSelect>
       <VForm>
         <VCard>

TypeError: Cannot use 'in' operator to search for 'cc' in null
    at Proxy.set 


Run Code Online (Sandbox Code Playgroud)

Adi*_*ya 8

我找出了哪里出错了,在我的模板中v-model我使用了this.school, this.namethis.cc这导致了警告的出现,但我仍然不清楚工作的内部结构。我想如果有人向我指出正确的资源。


小智 0

简单的解决方案:为您使用 v-for 的数据集添加 v-if 检查。也许你需template要这样做。