如何在vue js中正确初始化数据?

时间:2020-11-09 08:00:07

标签: javascript firebase vue.js

在onChangeDistrict之后需要使用initTableData和initTableFiltered,我希望现在不使用它,而是仅使用initTableFiltered

data () {
  return {
    data: []
  }
},
created () {
  this.initTableData()
},
methods() {
  initTableData () {
  db.collection('example').orderBy('owner_name', 'asc').get().then(res => {
    res.forEach((doc) => {
      this.data.push({
        id: doc.id,
      })
    })
  })
},
initTableFiltered () {
  db.collection('filter').orderBy('name', 'asc').get().then(res => {
    res.forEach((doc) => {
      this.data.push({
        id: doc.id,
      })
    })
}
onChangeDistrict () {
  this.initTablefiltered()
}
}

那么如何初始化在onChangeDistrict上新鲜过滤的initTable?

1 个答案:

答案 0 :(得分:0)

您是否创建了数据变量?这不在代码中吗?
例如:

export default {
  data() {
    return {
      data: []
    }
  },
 ...

没有实例化数据,这是没有反应的...