国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

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

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

瀏覽:246日期: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
主站蜘蛛池模板: 临澧县| 平江县| 黔东| 甘孜县| 广西| 甘德县| 尚志市| 高青县| 周宁县| 本溪市| 滨海县| 神木县| 科技| 龙州县| 灵台县| 临湘市| 襄汾县| 阿拉善盟| 南漳县| 佳木斯市| 武胜县| 朔州市| 嵊州市| 凤冈县| 萍乡市| 阜新市| 娄底市| 黄浦区| 四子王旗| 珲春市| 丰县| 高淳县| 池州市| 合川市| 和龙市| 白玉县| 阳新县| 冕宁县| 迁西县| 玉溪市| 贺兰县|