How to use toast in api.js files in vue framework

problem description

  • vux for ui framework
  • main.js introduces toast
    import {Toast ,ToastPlugin} from "vux"
    Vue.use(ToastPlugin, {position: "middle"})
  • api.js uses toast
    import axios from "axios";
    
    axios.interceptors.response.use(data=> {
        return data;
      }, err=> {
        // console.log(err.response);
          if(err.response !== undefined && err.response.status == 400){
              console.log(err.response);
            // Message.error({message: err.response.message});
                console.log(this);
            this.$vux.toast.show({
               text: "hello billo..."
             })
            if(err.response.data.message === ""){
                sessionStorage.removeItem("user");
                this.$router.push({ path: "/webchat" });
            }
          }
           return Promise.reject(err);
       })
  • toast is undefined of the error this.$vux
  • File structure
src
 api
  api.js
  index.js
 main.js

the environmental background of the problems and what methods you have tried

  • introduce Toast module directly into api.js
import {Toast} from "vux"

prompt module not find.

  • error screenshot

clipboard.png

clipboard.png

  • import {Toast} from "vux" console.log(Toast) :

clipboard.png

ask me how to handle it so that vux"s Toast can be used normally in the anonymous function of api.js "s axios.interceptors.response.use.

Mar.14,2022

introduce

into api.js
import { Toast } from 'vux'

after

Toast.show({
    text: 'hello billo...'
})
Menu