【问题标题】:Use toast in successful axios request在成功的 axios 请求中使用 toast
【发布时间】:2021-04-29 11:26:25
【问题描述】:

我想在 axios 响应成功后添加 toast 通知。 当我创建一个 toast 组件并在 vue 中注册它时 app.component("ToastAlert", ToastAlert);

我怎样才能在这个函数中实际使用它?

axios.interceptors.response.use(
  (response) => {
     // want to use the toast notification here
     
     
     return response;
  },
  (error) => {
     // all 4xx/5xx responses will end here
     return Promise.reject(error);
  }
);

【问题讨论】:

    标签: vue.js vuejs3


    【解决方案1】:

    也许你需要看看: https://raoulkramer.de/vue-js-axios-interceptors-and-toast-notifications/

    在文件中定义 axios 和拦截器添加:

    import Vue from 'vue';
    

    并显示吐司

    Vue.$toast.show();
    

    【讨论】:

      猜你喜欢
      • 2020-08-09
      • 1970-01-01
      • 1970-01-01
      • 2020-11-11
      • 1970-01-01
      • 2023-02-11
      • 1970-01-01
      • 2020-08-26
      • 2021-04-09
      相关资源
      最近更新 更多