【问题标题】:How to initialize data correctly in vue js?如何在 vue js 中正确初始化数据?
【发布时间】:2021-02-21 03:25:02
【问题描述】:

在 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 上重新初始化 initTablefiltered 呢?

【问题讨论】:

    标签: javascript firebase vue.js


    【解决方案1】:

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

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

    如果不实例化您的数据,这不是反应式的......

    【讨论】:

      猜你喜欢
      • 2019-04-09
      • 2020-09-25
      • 2022-08-11
      • 1970-01-01
      • 2022-01-01
      • 2010-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多