vue.js - vue获取mongodb中的数据起初显示未定义,但还是可以渲染
仅有的幸福
仅有的幸福 2017-05-02 09:22:47
0
2
711
[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>)

这是报错信息,下面是我的代码部分。

    <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>

这是 一个组件 topic是通过我的getters会获取到的,通过actions向mongodb请求数据,看上去一切都很正常。。。
convertTag和timeToNow都是我自己写的filter

仅有的幸福
仅有的幸福

reply all(2)
世界只因有你

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>
小葫芦

topic.meta = undefined.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!