How to dynamically add a component to the current page according to the global response value in the global filter in axios

how to dynamically add a component to the current page based on the global backend response value in the global filter in axios

current page refers to-I don"t know which page it is. As long as the back end responds to me with this code value, I will add this component to the current page

userActivation is the component that displays the following code when it receives the backend response values of 103 and 1002:

import userActivation from "userActivation"
import Vue form "vue"
axios.interceptors.response.use(response => {
    let responseData = response.data
    switch(responseData.code) {
        case 103:
        case 1002:
            console.log(window.vue)
            Vue.component("user-activation", {
                template: "<button></button>"
            },)
            // vuerouter.replace("/userActivation")
            window.vue.$loading.close()
            throw SyntaxError()
            break
    }
    return responseData
}, error => {
    // 
    if("ECONNABORTED" === error.code) {
        window.vue.$loading.close()
        // window.vue.$Modal.alert({
        //     title: "",
        //     okText: "",
        //     onOk: () => {
        //         window.vue.$loading.show()
        //         return axios(error.config)
        //     }
        // })
        // throw SyntaxError()
    } else {
        //  
        switch(error.response.status) {
            case 403:
            case 404:
            case 500:
            case 503:
            case 504:
        }
        return Promise.reject(error)
    }
})
Jul.23,2021

Brother you use the variable to control whether the code of the interface is displayed or not, and then change this variable


to report the event to the root component of the page, and then the root component to display.


final solution:

create a new registrationAward.js file to introduce the components you want to display

import Vue from 'vue';
import registrationAward from './registrationAward.vue'
let instance;
export default {
  show(options = {}) {
    if (!instance) {
      const Indicator = Vue.extend(registrationAward)
      instance = new Indicator().$mount(document.createElement('div'))
      document.body.appendChild(instance.$el)
    }
  }
};

in axios

import userActivation from 'userActivation'
import Vue form 'vue'
// js
import registrationAward from 'registrationAward'
axios.interceptors.response.use(response => {
    let responseData = response.data
    switch(responseData.code) {
        case 103:
        case 1002:
            // 
            registrationAward.show()
            window.vue.$loading.close()
            throw SyntaxError()
            break
    }
    return responseData
}, error => {
    return Promise.reject(error)   
}
})
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1be5205-3174b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1be5205-3174b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?