【问题标题】:How to do something before Nextjs getStaticProps execution, eg Interceptor?在 Nextjs getStaticProps 执行之前如何做一些事情,例如拦截器?
【发布时间】:2020-12-05 18:02:16
【问题描述】:

我想拦截并添加通用头属性到getStaticProps中的所有请求调用,getServerSideProps在服务器端执行。

axios.interceptors.request.use(function (config) {
    // Do something before request is sent
    // Ex: Add some common header props
    return config;
  }, function (error) {
    // Do something with request error
    return Promise.reject(error);
  });

【问题讨论】:

    标签: javascript axios next.js interceptor


    【解决方案1】:

    我和你有同样的问题。

    我搜索了很多,但找不到任何微小的解决方案。

    也许制作一个自定义的 Axios 实例组件。

    你可以用import customAxios from '../customAxios'代替import axios from "axios"

    【讨论】:

      猜你喜欢
      • 2022-01-10
      • 1970-01-01
      • 1970-01-01
      • 2019-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-11
      相关资源
      最近更新 更多