【问题标题】:Trying to check if properties exist with nuxt js尝试使用 nuxt js 检查属性是否存在
【发布时间】:2018-12-21 17:02:24
【问题描述】:

您好,我只是想检查 {{data.name}} 是否存在。 如果不存在就不要显示这个..

迭代:

<div v-if="conts.Titre || conts.keys(conts.Titre).length > 0" class="communes-contenu">

<div v-if="conts.Titre != ' '" class="communes-contenu">

<h3 v-if="conts.Titre">{{ conts.Titre }}</h3>

但什么都没有……只是一个 “无法读取属性 'Titre' of null”

谢谢!

【问题讨论】:

    标签: json vue.js vuejs2 conditional nuxt.js


    【解决方案1】:

    "Cannot read property 'Titre' of null"表示持有Titre的对象为空

    => conts 必须为空。

    您可以在同一个 v-if 中添加一个额外的检查 conts 是否存在,或者将其环绕。

    选项 1:

    <h3 v-if="conts && conts.Titre">{{ conts.Titre }}</h3>
    

    选项 2:

    <template v-if="conts">
        <h3 v-if="conts.Titre">{{ conts.Titre }}</h3>
    </template>
    

    【讨论】:

      猜你喜欢
      • 2016-02-19
      • 1970-01-01
      • 2018-02-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-28
      • 2020-03-21
      相关资源
      最近更新 更多