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

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

從多個(gè)數(shù)據(jù)源構(gòu)建 Nuxt 站點(diǎn)地圖

從多個(gè)數(shù)據(jù)源構(gòu)建 Nuxt 站點(diǎn)地圖

蝴蝶不菲 2023-08-18 10:17:40
我正在 SSR 模式下使用 Nuxt,并希望為多個(gè)路線/數(shù)據(jù)集構(gòu)建動(dòng)態(tài)站點(diǎn)地圖。我現(xiàn)在面臨的問(wèn)題是 async/await 函數(shù)只允許“data”作為變量。使用“post”作為變量的相同函數(shù)會(huì)導(dǎo)致“地圖函數(shù)不存在”這是我的 Nuxt.config.js 文件中的內(nèi)容  sitemap: {    hostname: "https://example.com",    routes: async () => {      let { data } = await axios.get('https://api.example.com/api/v1/locations');      data = data.data.map((loc) => `/locations/${loc.slug}`);      console.log(data);      let { posts } = await axios.get('https://cms.example.com/wp-json/wp/v2/posts');      posts = posts.map((post) => `/posts/${post.slug}`);      console.log(posts);      data.concat(posts);      return data    },    path: '/sitemap.xml'  }我正在尋找的結(jié)果輸出應(yīng)采用如下格式:[  '/locations/location-one',  '/locations/location-two',  '/locations/location-three',  '/posts/post-one',  '/posts/post-two',  '/posts/post-three',]我收到的錯(cuò)誤:Cannot read property 'map' of undefined它發(fā)生在這條線上:posts = posts.map((post) => `/posts/${post.slug}`)所以在我看來(lái),它不接受“posts”作為其自己的等待函數(shù)的有效變量。當(dāng)?shù)谝粋€(gè)調(diào)用被注釋掉并且使用“數(shù)據(jù)”而不是“帖子”時(shí),該調(diào)用工作正常
查看完整描述

2 回答

?
斯蒂芬大帝

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

你的解構(gòu)反應(yīng)是錯(cuò)誤的:

代替:

let { posts } = ...

經(jīng)過(guò):

let { data: posts } = ...

因?yàn)?Axios 總是返回一個(gè)“data”屬性,所以你只需將其重命名為“posts”即可。


查看完整回答
反對(duì) 回復(fù) 2023-08-18
?
交互式愛(ài)情

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

你的數(shù)組串聯(lián)必須是這樣的:

data.concat(posts);

push()方法僅推送一項(xiàng),而不是推送一組項(xiàng)目。

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

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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