小编XPD*_*XPD的帖子

React Hooks:使用 axios 拦截器显示全局微调器?

我想添加一个 Loader 组件,以便在React 中进行 API 调用时呈现。我想使用react context + hooks 而不是 redux

正如反应钩子的规则所说,我们不应该在反应组件之外使用反应钩子。但是我需要在Axios拦截器内部分派SHOW_LOADER和,如下所示。HIDE_LOADER

有没有办法实现这一目标?

import axios from "axios";
axios.interceptors.request.use(
  config => {
    dispatch({
    type: "SHOW_LOADER"
})
    return config;
  },
  error => {
     dispatch({
    type: "HIDE_LOADER"
})
    return Promise.reject(error);
  }
);

axios.interceptors.response.use(
  response => {
    dispatch({
    type: "HIDE_LOADER"
})
    return response;
  },
  error => {
    dispatch({
    type: "HIDE_LOADER"
})
    return Promise.reject(error);
  }
);
function GlobalLoader(){
    const [state,dispatch] = useContext(LoaderContext);
    return(
        <div>
            {
                state.loadStatus …
Run Code Online (Sandbox Code Playgroud)

interceptor reactjs axios react-context react-hooks

9
推荐指数
1
解决办法
8609
查看次数

将文件名从 .js 更改为 .jsx 后,React 项目无法编译

我遇到了一些障碍。

我意识到我项目的一个合作伙伴设置了一个文件.js而不是.jsx. 我切换了文件类型以匹配项目中的其余文件,现在我遇到了这个错误。

index.js:1 ./src/Components/SignUp/SignUp.js 错误:ENOENT:没有这样的文件或目录,打开“~/src/Components/SignUp/SignUp.js”

我替换了“~”的一些路径。

我已经在我的项目中搜索了所有实例,SignUp但找不到任何似乎将其锁定为查找 .js 文件的内容。有没有人有什么建议?

javascript jsx reactjs

6
推荐指数
1
解决办法
2245
查看次数

一旦解除了 boostrap vue 警报,它就不再工作了

我正在尝试使用bootstrap vue alert构建一个全局警报组件。我正在使用store 来保持警戒状态。vuex

下面是我的警报组件Alert.vue

<template>
  <b-alert show :variant="variant" dismissible> {{ message }} </b-alert>
</template>
<script>
export default {
  props: {
    variant: String,
    message: String
  },
  data() {
    return {};
  },
  name: "Alert",

  methods: {},
  computed: {}
};
</script>
<style scoped></style>
Run Code Online (Sandbox Code Playgroud)

下面是我的vuex店铺

const alert = {
  namespaced: true,
  state: {
    variant: "",
    message: "",
    showAlert: false
  },
  getters: {
    variant: state => state.variant,
    message: state => state.message,
    showAlert: state => state.showAlert
  }, …
Run Code Online (Sandbox Code Playgroud)

javascript vue.js bootstrap-4 bootstrap-vue

4
推荐指数
1
解决办法
3381
查看次数

Owin 身份验证不发出 cookie

我在登录控制器中有以下操作。出于测试目的,我没有在 Index 操作中使用登录表单。相反,我创建了声明身份并登录。此操作是 GET 而不是 POST。它创建一个声明标识并将其用于AuthenticationManager.SignIn. 但是当我检查浏览器 cookie 时,我找不到存在的身份验证 cookie。我想弄清楚出了什么问题。

    [AllowAnonymous]
    public ActionResult Index()
    {
        var identity = new ClaimsIdentity(DefaultAuthenticationTypes.ApplicationCookie);
        identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, "30"));
        identity.AddClaim(new Claim(ClaimTypes.Name, "JFid"));
        identity.AddClaim(new Claim(ClaimTypes.Email, "test"));

        AuthenticationManager.SignIn(new AuthenticationProperties()
        {
            IsPersistent = true,
            ExpiresUtc = DateTime.UtcNow.AddDays(7)

        }, identity);

        return View();
    }
Run Code Online (Sandbox Code Playgroud)

而且我还在 OWIN 中启用了 cookie 身份验证。

[assembly: OwinStartup(typeof(D.Support.WebStartup))]
namespace D.Support
{
    public class WebStartup
    {
        public void Configuration(IAppBuilder app)
        {

        app.UseCookieAuthentication(new Microsoft.Owin.Security.Cookies.CookieAuthenticationOptions()
        {
            LoginPath = new PathString("/MyLoginPath"),
            CookieName = "MyCookieName",
            CookieHttpOnly = true,

        });
        }
    } …
Run Code Online (Sandbox Code Playgroud)

asp.net asp.net-mvc owin asp.net-identity owin-middleware

3
推荐指数
1
解决办法
2113
查看次数

无法在Windows上启动TomEE?

这是cmd输出......

----------------------------------------------------------------

Installing the service 'TomEE' ...
Using CATALINA_HOME:    "C:\tomee"
Using CATALINA_BASE:    "C:\tomee"
Using JAVA_HOME:        "C:\program files\Java\jdk1.6.0_26"
Using JRE_HOME:         "C:\program files\Java\jdk1.6.0_26\jre"
Using JVM:              "C:\program files\Java\jdk1.6.0_26\jre\bin\server\jvm.dl
l"
""C:\tomee\bin\TomEE.x86.exe"" //IS//TomEE
[2013-04-09 16:16:39] [error] Unrecognized cmd option C:\tomee\bin\TomEE.x86.exe

[2013-04-09 16:16:39] [error] The specified module could not be found.
[2013-04-09 16:16:39] [error] Invalid command line arguments
[2013-04-09 16:16:39] [error] The specified module could not be found.
[2013-04-09 16:16:39] [error] Commons Daemon procrun failed with exit value: 1 (
Failed to parse command line arguments) …
Run Code Online (Sandbox Code Playgroud)

install ejb java-ee openejb

0
推荐指数
1
解决办法
3989
查看次数