久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

vue.js - vue獲取mongodb中的數據起初顯示未定義,但還是可以渲染

瀏覽:282日期:2024-03-29 11:55:28

問題描述

[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

問題解答

回答1:

這樣的你應該先判斷存在topic.meta對象在去去它的屬性,這樣就不報錯了,報錯的原因就是你沒有獲得meta數據的時候去獲取它的屬性

<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>回答2:

topic.meta = undefined.

標簽: vue
主站蜘蛛池模板: 蓝田县| 环江| 怀化市| 聂荣县| 永定县| 通许县| 宁阳县| 通山县| 舒兰市| 崇明县| 额济纳旗| 柳林县| 板桥市| 鹤壁市| 辽宁省| 云林县| 邵武市| 延边| 胶南市| 西青区| 五莲县| 资源县| 湟源县| 卢湾区| 永顺县| 沐川县| 屏边| 时尚| 涡阳县| 金门县| 东明县| 新泰市| 多伦县| 双城市| 宁海县| 南和县| 勐海县| 邵东县| 平定县| 白水县| 英山县|