In vue+typescript, use axios to report an error?

uses axios, in a new typescript project in vue-cli3.0, so it introduces

in main.ts.
import axios from "axios";
Vue.prototype.$axios = axios;
axios.defaults.baseURL = "http://192.168.1.225:8088";

error is reported in vue file

this is the method I used in js before. This time I started to use ts to report an error. How should I solve it? Thank you for your answer, thank you


in ts, $axios, cannot be hung on the prototype chain if it is not recognized under vue. It can be used in another way

import axios from 'axios'
import Vueaxios from 'vue-axios'
Vue.use(Vueaxios, axios)

then this.axios directly in vue


import axios form 'axios';
axios.post(
...
)

this.$XXX needs to be mounted in new vue

such as this.$router
this.$store
this.$t ()
this

import axios from 'axios' Direct axios. Just use it

Menu