[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"$KiqIp5Qu8t":3,"vue-tips-\u002Fvue-tips\u002Fchange-status-code-of-the-response":52,"blogToc-\u002Fvue-tips\u002Fchange-status-code-of-the-response":408,"vue-tips-surrounding-\u002Fvue-tips\u002Fchange-status-code-of-the-response":643},{"id":4,"extension":5,"items":6,"meta":49,"stem":50,"__hash__":51},"menu\u002Fmenu.json","json",[7,12,16,20,24,28,32,36,41,45],{"i18nId":8,"to":9,"ariaLabel":10,"mainNavigation":11},"components.menu.home","\u002F","Home",true,{"i18nId":13,"to":14,"ariaLabel":15,"mainNavigation":11},"components.menu.about","\u002Fhire-me","About",{"i18nId":17,"to":18,"ariaLabel":19,"mainNavigation":11},"components.menu.testimonials","\u002Ftestimonials","Testimonials",{"i18nId":21,"to":22,"ariaLabel":23},"components.menu.contact","\u002Fcontact","Contact",{"i18nId":25,"to":26,"ariaLabel":27,"mainNavigation":11},"components.menu.blog","\u002Fblog","Blog",{"i18nId":29,"to":30,"ariaLabel":31,"mainNavigation":11},"components.menu.tips","\u002Fvue-tips","Vue Tips",{"i18nId":33,"to":34,"ariaLabel":35,"mainNavigation":11},"components.menu.projects","\u002Fprojects","Projects",{"i18nId":37,"to":38,"ariaLabel":39,"mainNavigation":40},"components.menu.stats","\u002Fstats","stats",false,{"i18nId":42,"to":43,"ariaLabel":44,"mainNavigation":40},"components.menu.businessCard","\u002Fbusiness-card","Business Card",{"i18nId":46,"to":47,"ariaLabel":48,"mainNavigation":40},"components.menu.publications","\u002Fpublications","Publications",{},"menu","njLT1QoRt2Dv8QWoVmH8xdTAiDywSj0bxBQdmoyWUE0",{"id":53,"title":54,"body":55,"categories":390,"cover":392,"date":393,"description":394,"extension":395,"lastUpdated":396,"meta":397,"navigation":11,"ogImage":396,"path":398,"readingTime":399,"robots":396,"schemaOrg":396,"seo":404,"sitemap":405,"stem":406,"tags":396,"__hash__":407},"vueTips\u002Fvue-tips\u002Fchange-status-code-of-the-response\u002Findex.md","Nuxt Tip: Change Status Code of the Response",{"type":56,"value":57,"toc":387},"minimark",[58,70,79,82,182,191,198,354,368,373,380,383],[59,60,61,62,69],"p",{},"Nuxt provides the ",[63,64,68],"a",{"href":65,"rel":66},"https:\u002F\u002Fnuxt.com\u002Fdocs\u002Fapi\u002Futils\u002Fset-response-status",[67],"nofollow","setResponseStatus"," composable to set the status code (and optionally the status message) of the response.",[59,71,72,73,78],{},"This composable only works on the server and will have no effect on the client. Additionally, it can only be used in the ",[63,74,77],{"href":75,"rel":76},"https:\u002F\u002Fnuxt.com\u002Fdocs\u002Fguide\u002Fgoing-further\u002Fnuxt-app#the-nuxt-context",[67],"Nuxt Content",". The Nuxt context is only accessible in plugins, Nuxt hooks, Nuxt middleware, and setup functions (in pages and components).",[59,80,81],{},"Let's take a look at how to use it:",[83,84,92],"pre",{"className":85,"code":86,"highlights":87,"language":90,"meta":91,"style":91},"language-ts shiki shiki-themes github-light poimandres poimandres","const event = useRequestEvent()\n\nif (event) {\n  setResponseStatus(event, 404, 'Page Not Found')\n}\n",[88,89],1,4,"ts","",[93,94,95,120,126,143,176],"code",{"__ignoreMap":91},[96,97,101,105,109,112,116],"span",{"class":98,"line":88},[99,100],"line","highlight",[96,102,104],{"class":103},"slWGy","const",[96,106,108],{"class":107},"sGRIV"," event",[96,110,111],{"class":103}," =",[96,113,115],{"class":114},"sHQ3f"," useRequestEvent",[96,117,119],{"class":118},"sygvE","()\n",[96,121,123],{"class":99,"line":122},2,[96,124,125],{"emptyLinePlaceholder":11},"\n",[96,127,129,133,136,140],{"class":99,"line":128},3,[96,130,132],{"class":131},"sOygg","if",[96,134,135],{"class":118}," (",[96,137,139],{"class":138},"sMzB8","event",[96,141,142],{"class":118},") {\n",[96,144,146,149,152,154,157,161,163,167,171,173],{"class":145,"line":89},[99,100],[96,147,148],{"class":114},"  setResponseStatus",[96,150,151],{"class":118},"(",[96,153,139],{"class":138},[96,155,156],{"class":118},", ",[96,158,160],{"class":159},"s6g4C","404",[96,162,156],{"class":118},[96,164,166],{"class":165},"srEIG","'",[96,168,170],{"class":169},"skTdI","Page Not Found",[96,172,166],{"class":165},[96,174,175],{"class":118},")\n",[96,177,179],{"class":99,"line":178},5,[96,180,181],{"class":118},"}\n",[59,183,184,186,187,190],{},[93,185,139],{}," will be ",[93,188,189],{},"undefined"," in the browser, so you can safely use this composable in your Nuxt content.",[59,192,193,194,197],{},"In my client's project, I used this composable to set the status code of the response to ",[93,195,196],{},"410"," when a product has expired. This way, the search engines will know that the product is no longer available and will remove it from the search results:",[83,199,204],{"className":200,"code":201,"filename":202,"language":203,"meta":91,"style":91},"language-vue shiki shiki-themes github-light poimandres poimandres","\u003Cscript setup lang=\"ts\">\nconst { data, error } = await useFetch('\u002Fapi\u002Fproduct');\n\nconst event = useRequestEvent();\n\nif (event && data.value?.isGone) {\n  setResponseStatus(event, 410);\n}\n\u003C\u002Fscript>\n","ProductPage.vue","vue",[93,205,206,235,274,278,291,295,324,339,344],{"__ignoreMap":91},[96,207,208,211,215,219,222,225,228,230,232],{"class":99,"line":88},[96,209,210],{"class":138},"\u003C",[96,212,214],{"class":213},"s8PnL","script",[96,216,218],{"class":217},"sppiw"," setup",[96,220,221],{"class":217}," lang",[96,223,224],{"class":118},"=",[96,226,227],{"class":165},"\"",[96,229,90],{"class":169},[96,231,227],{"class":165},[96,233,234],{"class":138},">\n",[96,236,237,239,242,245,247,250,253,255,259,262,264,266,269,271],{"class":99,"line":122},[96,238,104],{"class":103},[96,240,241],{"class":118}," { ",[96,243,244],{"class":107},"data",[96,246,156],{"class":118},[96,248,249],{"class":107},"error",[96,251,252],{"class":118}," } ",[96,254,224],{"class":103},[96,256,258],{"class":257},"sdZ-l"," await",[96,260,261],{"class":114}," useFetch",[96,263,151],{"class":118},[96,265,166],{"class":165},[96,267,268],{"class":169},"\u002Fapi\u002Fproduct",[96,270,166],{"class":165},[96,272,273],{"class":118},");\n",[96,275,276],{"class":99,"line":128},[96,277,125],{"emptyLinePlaceholder":11},[96,279,280,282,284,286,288],{"class":99,"line":89},[96,281,104],{"class":103},[96,283,108],{"class":107},[96,285,111],{"class":103},[96,287,115],{"class":114},[96,289,290],{"class":118},"();\n",[96,292,293],{"class":99,"line":178},[96,294,125],{"emptyLinePlaceholder":11},[96,296,298,300,302,304,307,310,313,316,319,322],{"class":99,"line":297},6,[96,299,132],{"class":131},[96,301,135],{"class":118},[96,303,139],{"class":138},[96,305,306],{"class":103}," &&",[96,308,309],{"class":138}," data",[96,311,312],{"class":118},".",[96,314,315],{"class":138},"value",[96,317,318],{"class":118},"?.",[96,320,321],{"class":138},"isGone",[96,323,142],{"class":118},[96,325,327,329,331,333,335,337],{"class":99,"line":326},7,[96,328,148],{"class":114},[96,330,151],{"class":118},[96,332,139],{"class":138},[96,334,156],{"class":118},[96,336,196],{"class":159},[96,338,273],{"class":118},[96,340,342],{"class":99,"line":341},8,[96,343,181],{"class":118},[96,345,347,350,352],{"class":99,"line":346},9,[96,348,349],{"class":138},"\u003C\u002F",[96,351,214],{"class":213},[96,353,234],{"class":138},[59,355,356,357,360,361,363,364,367],{},"The important part here is to await the ",[93,358,359],{},"useFetch"," composable to be able to read evaluate the ",[93,362,244],{}," value inside the ",[93,365,366],{},"script setup"," tag.",[369,370,372],"h2",{"id":371},"stackblitz","StackBlitz",[59,374,375,376,312],{},"You can play with the code in this ",[63,377,372],{"href":378,"rel":379},"https:\u002F\u002Fstackblitz.com\u002Fedit\u002Fnuxt-set-response-status?file=pages\u002Findex.vue",[67],[371,381],{"project-id":382},"nuxt-change-status-code-of-the-response",[384,385,386],"style",{},"html pre.shiki code .slWGy, html code.shiki .slWGy{--shiki-light:#D73A49;--shiki-default:#91B4D5;--shiki-dark:#91B4D5}html pre.shiki code .sGRIV, html code.shiki .sGRIV{--shiki-light:#005CC5;--shiki-default:#E4F0FB;--shiki-dark:#E4F0FB}html pre.shiki code .sHQ3f, html code.shiki .sHQ3f{--shiki-light:#6F42C1;--shiki-default:#E4F0FBD0;--shiki-dark:#E4F0FBD0}html pre.shiki code .sygvE, html code.shiki .sygvE{--shiki-light:#24292E;--shiki-default:#A6ACCD;--shiki-dark:#A6ACCD}html pre.shiki code .sOygg, html code.shiki .sOygg{--shiki-light:#D73A49;--shiki-default:#A6ACCD;--shiki-dark:#A6ACCD}html pre.shiki code .sMzB8, html code.shiki .sMzB8{--shiki-light:#24292E;--shiki-default:#E4F0FB;--shiki-dark:#E4F0FB}html pre.shiki code .s6g4C, html code.shiki .s6g4C{--shiki-light:#005CC5;--shiki-default:#5DE4C7;--shiki-dark:#5DE4C7}html pre.shiki code .srEIG, html code.shiki .srEIG{--shiki-light:#032F62;--shiki-default:#A6ACCD;--shiki-dark:#A6ACCD}html pre.shiki code .skTdI, html code.shiki .skTdI{--shiki-light:#032F62;--shiki-default:#5DE4C7;--shiki-dark:#5DE4C7}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .s8PnL, html code.shiki .s8PnL{--shiki-light:#22863A;--shiki-default:#5DE4C7;--shiki-dark:#5DE4C7}html pre.shiki code .sppiw, html code.shiki .sppiw{--shiki-light:#6F42C1;--shiki-light-font-style:inherit;--shiki-default:#91B4D5;--shiki-default-font-style:italic;--shiki-dark:#91B4D5;--shiki-dark-font-style:italic}html pre.shiki code .sdZ-l, html code.shiki .sdZ-l{--shiki-light:#D73A49;--shiki-default:#5DE4C7C0;--shiki-dark:#5DE4C7C0}",{"title":91,"searchDepth":122,"depth":122,"links":388},[389],{"id":371,"depth":122,"text":372},[391],"nuxt","vue-tips\u002Fnuxt-change-status-code-of-the-response\u002Fog.png","2024-06-13","`setResponseStatus` is a Nuxt composable to set the status code and (and optionally the status message) of the response.","md",null,{},"\u002Fvue-tips\u002Fchange-status-code-of-the-response",{"text":400,"minutes":401,"time":402,"words":403},"1 min read",0.95,57000,190,{"title":54,"description":394},{"loc":398,"lastmod":393},"vue-tips\u002Fchange-status-code-of-the-response\u002Findex","oASYPY5EspoCa2nFneDFUbDWv8wHbvnw_8I5POY7xPQ",{"id":409,"title":54,"body":410,"cover":392,"description":394,"extension":395,"meta":637,"navigation":11,"path":398,"robots":396,"seo":640,"sitemap":641,"stem":406,"__hash__":642},"content\u002Fvue-tips\u002Fchange-status-code-of-the-response\u002Findex.md",{"type":56,"value":411,"toc":634},[412,417,422,424,483,489,493,615,623,625,630,632],[59,413,61,414,69],{},[63,415,68],{"href":65,"rel":416},[67],[59,418,72,419,78],{},[63,420,77],{"href":75,"rel":421},[67],[59,423,81],{},[83,425,427],{"className":85,"code":86,"highlights":426,"language":90,"meta":91,"style":91},[88,89],[93,428,429,442,446,456,479],{"__ignoreMap":91},[96,430,432,434,436,438,440],{"class":431,"line":88},[99,100],[96,433,104],{"class":103},[96,435,108],{"class":107},[96,437,111],{"class":103},[96,439,115],{"class":114},[96,441,119],{"class":118},[96,443,444],{"class":99,"line":122},[96,445,125],{"emptyLinePlaceholder":11},[96,447,448,450,452,454],{"class":99,"line":128},[96,449,132],{"class":131},[96,451,135],{"class":118},[96,453,139],{"class":138},[96,455,142],{"class":118},[96,457,459,461,463,465,467,469,471,473,475,477],{"class":458,"line":89},[99,100],[96,460,148],{"class":114},[96,462,151],{"class":118},[96,464,139],{"class":138},[96,466,156],{"class":118},[96,468,160],{"class":159},[96,470,156],{"class":118},[96,472,166],{"class":165},[96,474,170],{"class":169},[96,476,166],{"class":165},[96,478,175],{"class":118},[96,480,481],{"class":99,"line":178},[96,482,181],{"class":118},[59,484,485,186,487,190],{},[93,486,139],{},[93,488,189],{},[59,490,193,491,197],{},[93,492,196],{},[83,494,495],{"className":200,"code":201,"filename":202,"language":203,"meta":91,"style":91},[93,496,497,517,547,551,563,567,589,603,607],{"__ignoreMap":91},[96,498,499,501,503,505,507,509,511,513,515],{"class":99,"line":88},[96,500,210],{"class":138},[96,502,214],{"class":213},[96,504,218],{"class":217},[96,506,221],{"class":217},[96,508,224],{"class":118},[96,510,227],{"class":165},[96,512,90],{"class":169},[96,514,227],{"class":165},[96,516,234],{"class":138},[96,518,519,521,523,525,527,529,531,533,535,537,539,541,543,545],{"class":99,"line":122},[96,520,104],{"class":103},[96,522,241],{"class":118},[96,524,244],{"class":107},[96,526,156],{"class":118},[96,528,249],{"class":107},[96,530,252],{"class":118},[96,532,224],{"class":103},[96,534,258],{"class":257},[96,536,261],{"class":114},[96,538,151],{"class":118},[96,540,166],{"class":165},[96,542,268],{"class":169},[96,544,166],{"class":165},[96,546,273],{"class":118},[96,548,549],{"class":99,"line":128},[96,550,125],{"emptyLinePlaceholder":11},[96,552,553,555,557,559,561],{"class":99,"line":89},[96,554,104],{"class":103},[96,556,108],{"class":107},[96,558,111],{"class":103},[96,560,115],{"class":114},[96,562,290],{"class":118},[96,564,565],{"class":99,"line":178},[96,566,125],{"emptyLinePlaceholder":11},[96,568,569,571,573,575,577,579,581,583,585,587],{"class":99,"line":297},[96,570,132],{"class":131},[96,572,135],{"class":118},[96,574,139],{"class":138},[96,576,306],{"class":103},[96,578,309],{"class":138},[96,580,312],{"class":118},[96,582,315],{"class":138},[96,584,318],{"class":118},[96,586,321],{"class":138},[96,588,142],{"class":118},[96,590,591,593,595,597,599,601],{"class":99,"line":326},[96,592,148],{"class":114},[96,594,151],{"class":118},[96,596,139],{"class":138},[96,598,156],{"class":118},[96,600,196],{"class":159},[96,602,273],{"class":118},[96,604,605],{"class":99,"line":341},[96,606,181],{"class":118},[96,608,609,611,613],{"class":99,"line":346},[96,610,349],{"class":138},[96,612,214],{"class":213},[96,614,234],{"class":138},[59,616,356,617,360,619,363,621,367],{},[93,618,359],{},[93,620,244],{},[93,622,366],{},[369,624,372],{"id":371},[59,626,375,627,312],{},[63,628,372],{"href":378,"rel":629},[67],[371,631],{"project-id":382},[384,633,386],{},{"title":91,"searchDepth":122,"depth":122,"links":635},[636],{"id":371,"depth":122,"text":372},{"categories":638,"date":393,"readingTime":639},[391],{"text":400,"minutes":401,"time":402,"words":403},{"title":54,"description":394},{"loc":398,"lastmod":393},"orT8eeUb6rcHdHYjMr-hsrNqALjaL3kK6VOROXPwHPk",[644,648],{"title":645,"path":646,"stem":647,"children":-1},"Vue Tip: Cache Component Instances With the KeepAlive Component","\u002Fvue-tips\u002Fcache-component-instances-with-the-keep-alive-component","vue-tips\u002Fcache-component-instances-with-the-keep-alive-component\u002Findex",{"title":649,"path":650,"stem":651,"children":-1},"Nuxt Tip: Run Code Once During SSR or CSR","\u002Fvue-tips\u002Fnuxt-run-code-once-during-ssr-or-csr","vue-tips\u002Fnuxt-run-code-once-during-ssr-or-csr\u002Findex"]