No--09 a little bit of a problem today Axios global Registration

Source: Internet
Author: User

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.jsIntroduced 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 .vueWhen used in a file, note axiosBefore 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.