【问题标题】:Keep getting error "is not defined on the instance but referenced during render"不断收到错误“未在实例上定义但在渲染期间被引用”
【发布时间】:2023-01-03 03:20:09
【问题描述】:

将我的数据组件绑定到模板后,我不断收到以下错误。任何帮助,将不胜感激。

脚本:

data() {
  return {
    sireDetailsData: [],
    horse_show_name_prop:,
  }
},

async created () {
  const psireName = await this.sireName;

  console.log(psireName)

  try {
    const response = await sireDetails.fetchHorseIndex(psireName);

    this.sireDetailsData = response.data;

    try {
      this.horse_show_name_prop = this.sireDetailsData[0].horse_details[0].horse_show_name
    } catch (error) {
      this.horse_show_name_prop = undefined
    }
  } catch (error) {
    console.error(error);
  }
},

模板:

<a-col
  :span="6"
  :md="6"
  align="middle"
  style="margin-right: 0px;"
  :horse_name="horse_show_name_prop"
>
  <p
    class="m-0 text-sm font-bold center"
    style="min-width: 0px;"
    v-if="horse_name !== undefined"
  >
    {{ horse_name }}%
  </p>

  <p
    class="m-0 text-sm font-bold center"
    style="min-width: 0px;"
    v-else
  >
    -
  </p>

  <a-tag
    class="ant-tag-primary font-semibold text-xs"
    style="min-width: 30px;margin-right: 0px;"
  >
    Win %
  </a-tag>
</a-col>

在进行一些实时更改后,数据就会加载进来。这让我觉得事情呈现出了乱序。

【问题讨论】:

  • 您可能需要等待 fetchHorseIndex 完成。见:stackoverflow.com/a/62830489/17438890
  • 如果您使用 fetch 来获取数据,请展示您的数据结构,因为我们不应该猜测它。

标签: vue.js vue-component


【解决方案1】:

您需要在数据中声明horse_name

       data() {
            return {
                sireDetailsData: [],
                horse_show_name_prop:,
                horse_name: '', // Add horse_name here
            }
        },

【讨论】:

    猜你喜欢
    • 2019-12-08
    • 2017-02-13
    • 2017-02-17
    • 1970-01-01
    • 2018-12-24
    • 2018-06-05
    • 2018-09-17
    • 2022-07-14
    • 2021-11-16
    相关资源
    最近更新 更多