第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

使用 .find 方法不會(huì)從解析的 JSON 返回對(duì)象

使用 .find 方法不會(huì)從解析的 JSON 返回對(duì)象

qq_笑_17 2023-06-29 22:34:46
我正在使用 Vue.js 3,但我認(rèn)為這與我的問(wèn)題無(wú)關(guān)。我調(diào)用 localStorage 來(lái)獲取帖子對(duì)象的 JSON 數(shù)組,對(duì)其進(jìn)行解析,然后使用 id 來(lái)查找帖子。我從路線中獲取 id 沒(méi)有問(wèn)題,但使用 .find 搜索解析的數(shù)組返回未定義。Post.vue 文件? ? created() {? ? ? ? this.postId = this.$route.params.id;? ? ? ? console.log("******? ? POST ID *********");? ? ? ? console.log(this.postId);? ? ? ? var posts = JSON.parse(localStorage.getItem("posts"));? ? ? ? console.log("******? ? POSTS ARRAY *********");? ? ? ? console.log(posts);? ? ? ? this.post = posts.find(post => post.id === this.postId);? ? ? ? console.log("****** POST *********");? ? ? ? console.log(this.post);? ? ? ??? ? }
查看完整描述

1 回答

?
12345678_0001

TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超5個(gè)贊

類(lèi)型this.postId為字符串,數(shù)組中每個(gè)對(duì)象的id類(lèi)型posts為數(shù)字。所以你可以使用==代替===. 或者使用 將 的類(lèi)型更改this.postId為數(shù)字parseInt。



查看完整回答
反對(duì) 回復(fù) 2023-06-29
  • 1 回答
  • 0 關(guān)注
  • 135 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)