码迷,mamicode.com
首页 > 移动开发 > 详细

axios 安装使用

时间:2019-10-27 15:04:38      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:func   ios   无法   data   cat   OLE   post   erro   cti   

命令:
cnpm install axios -D

在main.js 中引入:

    `import axios from 'axios'`

技术图片

这时候如果在其它的组件中,是无法使用 axios 命令的。但如果将 axios 改写为 Vue 的原型属性,就能解决这个问题

Vue.prototype.$ajax = axios

在其他组件都可以用:


methods: {

 submitForm () {

 this.$ajax({

  method: 'post',

  url: '/user',

  data: {

  name: 'wise',

  info: 'wrong'

  }

 })

}

使用:

          Vue.prototype.$ajax = axios
            //在组件中这样使用
            this.$http.get().then(function (response) {
                    console.log(response);
            }).catch(function (error) {
                    console.log(error);
            });

技术图片

下图为vue加载json的配置部分:

技术图片

axios 安装使用

标签:func   ios   无法   data   cat   OLE   post   erro   cti   

原文地址:https://www.cnblogs.com/panghu123/p/11746506.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!