search

Home  >  Q&A  >  body text

vue.js - Vue gets the data in mongodb and it appears undefined at first, but it can still be rendered.

[Vue warn]: Error when evaluating expression "topic.meta.createAt != topic.meta.updateAt": TypeError: Cannot read property 'createAt' of undefined (found in component: <v-article>)

[Vue warn]: Error when evaluating expression "topic.meta.createAt": TypeError: Cannot read property 'createAt' of undefined (found in component: <v-article>)

This is the error message. Below is my code part.

    <h1>{{ topic.title }}</h1>
    <p class="info">
      <a v-for="tag in topic.tag" v-link="{name: 'tab', params: {tab: tag, page: 1}}" class="tag">
        {{ tag | convertTag}}
      </a>
      <a class="name"><strong>radical</strong></a>
      <span class="ask">{{ topic.meta.createAt | timeToNow }}&nbsp;发布</span>
      <span v-if="topic.meta.createAt != topic.meta.updateAt" class="update">{{ topic.meta.updateAt | timeToNow }}&nbsp;更新</span>
    </p>

This is a component topic that is obtained through my getters. It requests data from mongodb through actions. Everything seems to be normal. . .
convertTag and timeToNow are both filters written by me

仅有的幸福仅有的幸福2789 days ago767

reply all(2)I'll reply

  • 世界只因有你

    世界只因有你2017-05-02 09:24:47

    In this case, you should first determine that the topic.meta object exists and get its attributes, so that no error is reported.
    The reason for the error is that you get its attributes without getting the meta data

    <h1>{{ topic.title }}</h1>
        <p class="info">
          <a v-for="tag in topic.tag" v-link="{name: 'tab', params: {tab: tag, page: 1}}" class="tag">
            {{ tag | convertTag}}
          </a>
          <a class="name"><strong>radical</strong></a>
          <span v-if="!!topic.meta" class="ask">{{ topic.meta.createAt | timeToNow }}&nbsp;发布</span>
          <span v-if="!!topic.meta && topic.meta.createAt != topic.meta.updateAt" class="update">{{ topic.meta.updateAt | timeToNow }}&nbsp;更新</span>
        </p>

    reply
    0
  • 高洛峰

    高洛峰2017-05-02 09:24:47

    topic.meta = undefined.

    reply
    0
  • Cancelreply