Today using Vue to write the project, use axios
, because it axios
can not be used, Vue.use()
so in each file is required, the file is not good to .vue
axios
import
.vue
say, more than a bit of trouble.
Later thought, can not directly axios
add to Vue
the prototype, so that the global registration has been achieved.
1. First in
main.js
Introduced in
axios
import Vue from ‘vue‘import axios from ‘axios‘//把 `axios` 加到 `Vue` 的原型中Vue.prototype.axios = axios;new Vue({ el: ‘#app‘, render:h => h(App)})
2. In
.vue
When used in a file, note
axios
Before you add
this
<script>export default {name: ' app ', data () {return{msg: ' Hello '}}, methods:{Send () {//Note: Because Axios is added to the Vue prototype, the Axios method is used before the This this.axios.get ( ' https://www.baidu.com******* '). Span class= "hljs-function" >resp = {console.log ( Resp.data)}). catch (err = { Console.log (ERR); })}}}</SCRIPT>
Well, of course, the result is no problem! ;
No--09 a little bit of a problem today Axios global Registration