Vue.js中使用axios

来源:互联网 发布:tensorflow r语言 编辑:程序博客网 时间:2024/06/06 04:26

Vue.js中使用axios

最近自己做项目才知道vue2.0作者提倡使用axios代替vue resource,并且不再维护vue resource。

在vue-cli中使用axios的大致步骤如下:

一、安装axios

npm install axios

二、导入axios

在项目的main.js中

    import axios form 'axios'    this.prototype.$http =axios

三、使用axios

发送简单的get请求

this.$http.get('url')    .then(response => {        console.log(response)    }, error => {        console.log(error)    })
0 0