<legend id='I56mc'><style id='I56mc'><dir id='I56mc'><q id='I56mc'></q></dir></style></legend>

    1. <small id='I56mc'></small><noframes id='I56mc'>

      <tfoot id='I56mc'></tfoot>
    2. <i id='I56mc'><tr id='I56mc'><dt id='I56mc'><q id='I56mc'><span id='I56mc'><b id='I56mc'><form id='I56mc'><ins id='I56mc'></ins><ul id='I56mc'></ul><sub id='I56mc'></sub></form><legend id='I56mc'></legend><bdo id='I56mc'><pre id='I56mc'><center id='I56mc'></center></pre></bdo></b><th id='I56mc'></th></span></q></dt></tr></i><div id='I56mc'><tfoot id='I56mc'></tfoot><dl id='I56mc'><fieldset id='I56mc'></fieldset></dl></div>
      • <bdo id='I56mc'></bdo><ul id='I56mc'></ul>

        如何在 Nuxt 静态文件响应中添加标题?

        时间:2023-10-14
        <legend id='WF6qr'><style id='WF6qr'><dir id='WF6qr'><q id='WF6qr'></q></dir></style></legend>

        1. <i id='WF6qr'><tr id='WF6qr'><dt id='WF6qr'><q id='WF6qr'><span id='WF6qr'><b id='WF6qr'><form id='WF6qr'><ins id='WF6qr'></ins><ul id='WF6qr'></ul><sub id='WF6qr'></sub></form><legend id='WF6qr'></legend><bdo id='WF6qr'><pre id='WF6qr'><center id='WF6qr'></center></pre></bdo></b><th id='WF6qr'></th></span></q></dt></tr></i><div id='WF6qr'><tfoot id='WF6qr'></tfoot><dl id='WF6qr'><fieldset id='WF6qr'></fieldset></dl></div>
          <tfoot id='WF6qr'></tfoot>
              <tbody id='WF6qr'></tbody>
              • <small id='WF6qr'></small><noframes id='WF6qr'>

                  <bdo id='WF6qr'></bdo><ul id='WF6qr'></ul>
                • 本文介绍了如何在 Nuxt 静态文件响应中添加标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我在静态文件夹中有一个 json 文件,我正在尝试从另一个网站访问它,但我遇到了 CORS 问题.

                  I have a json file on static folder and I'm trying to access it from another web site, but I'm having problem with the CORS.

                  如何在静态文件响应中添加标头(如 Access-Control-Allow-Origin)?

                  How can I add headers (like Access-Control-Allow-Origin) on the static files response?

                  我试过这个 https://github.com/nuxt/nuxt.js/issues/2554#issuecomment-363795301,但不适用于静态文件.

                  I tried this https://github.com/nuxt/nuxt.js/issues/2554#issuecomment-363795301, but didn't work for static files.

                  module.exports = function (req, res, next) {
                      res.setHeader('Access-Control-Allow-Origin', '*');
                      res.setHeader('Access-Control-Allow-Headers', '*');
                      res.setHeader('Access-Control-Allow-Methods', '*');
                      next()
                  }
                  

                  推荐答案

                  Nuxt 有一个内置渲染属性选项,您可以在 nuxt.config.js 文件中使用它.

                  Nuxt has a build in render property option, that you can use inside the nuxt.config.js file.

                  如果您想为静态文件添加访问控制标头,只需使用 setHeaders 函数.

                  If you want to add Access-Control Headers for static files just use the setHeaders function.

                  参见 https://nuxtjs.org/api/configuration-render#static.

                  在后台 Nuxt 使用 serve-static 包(也适用于其他选项).

                  In the background Nuxt uses the serve-static package (also for other options).

                  例子:

                  render: {
                     static: {
                       setHeaders(res) {
                         res.setHeader('X-Frame-Options', 'ALLOWALL')
                         res.setHeader('Access-Control-Allow-Origin', '*')
                         res.setHeader('Access-Control-Allow-Methods', 'GET')
                         res.setHeader('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept')
                    }
                  }
                  

                  这篇关于如何在 Nuxt 静态文件响应中添加标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:尽管标头正确,但 CORS Access-Control-Allow-Origin 下一篇:使用 instagram api 的访问控制允许来源

                  相关文章

                  最新文章

                  <i id='z1chQ'><tr id='z1chQ'><dt id='z1chQ'><q id='z1chQ'><span id='z1chQ'><b id='z1chQ'><form id='z1chQ'><ins id='z1chQ'></ins><ul id='z1chQ'></ul><sub id='z1chQ'></sub></form><legend id='z1chQ'></legend><bdo id='z1chQ'><pre id='z1chQ'><center id='z1chQ'></center></pre></bdo></b><th id='z1chQ'></th></span></q></dt></tr></i><div id='z1chQ'><tfoot id='z1chQ'></tfoot><dl id='z1chQ'><fieldset id='z1chQ'></fieldset></dl></div>

                  <small id='z1chQ'></small><noframes id='z1chQ'>

                  <legend id='z1chQ'><style id='z1chQ'><dir id='z1chQ'><q id='z1chQ'></q></dir></style></legend>
                  <tfoot id='z1chQ'></tfoot>

                      • <bdo id='z1chQ'></bdo><ul id='z1chQ'></ul>