Vue interface encapsulation problem

Note: get and post are encapsulated in axios.js. Common.js sibling in the directory

clipboard.png

//common.js


//InstitutionSetup.vue


clipboard.png

Jan.14,2022

Vue.prototype.$axios = axios


the introduction of axios is not mounted on Vue. You can add Vue.prototype.axios = axios before export default and the following code can be used


this question
you should be Vue.prototype.common = common

this.login () this in this login is vue instance
this.common.login () this login this is common , not vue instance

this.common.login.call (this)

can be understood in this way

import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'
export default{
    login:function(){
        axios.get("", {})
        .then(res => {
            let { msg, code, data } = res.data;
            if (code !== 1) {
                this.$message({
                    message: msg,
                    type: "error"
                });
            } else {
                console.log(res);
            }
        })
        .catch(function(error) {
            console.log(error);
        });
    }
}
Menu