博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
vue使用axios请求后端数据
阅读量:6893 次
发布时间:2019-06-27

本文共 714 字,大约阅读时间需要 2 分钟。

1. 安装axios

$ npm install axios

2.在main.js里面导入axios

import axios from 'axios'Vue.prototype.$http = axios

3.下面就可以使用axios获取数据了

// 发送get请求// 向具有指定ID的用户发出请求this.$http.get('/user?ID=12345')  .then(response => {    console.log(response);  })// 错误处理  .catch(error => {    console.log(error);  });// 也可以通过 params 对象传递参数$http.get('/user', {    params: {      ID: 12345    }  })   .then(response => {    console.log(response);  })// 错误处理  .catch(error => {    console.log(error);  });
// 发送post请求this.$http.post('/user', {    firstName: 'Fred',    lastName: 'Flintstone'  })  .then(response => {    console.log(response);  })  .catch(error => {    console.log(error);  });

 

转载于:https://www.cnblogs.com/time-read/p/9322760.html

你可能感兴趣的文章
make 中的路径搜索(十二)
查看>>
zabbix agent 端主动注册
查看>>
初识Mysql(二)
查看>>
监控系统的状态
查看>>
Samba文件共享服务
查看>>
Check Point SMB 操作手册
查看>>
百万PV网站架构案例
查看>>
Redis PHP连接Redis
查看>>
苏研环境gerrit提交
查看>>
还在傻傻用Ctrl+C和Ctrl+V吗?这2个行列转置方法助你效率提80%!
查看>>
webpack4.0各个击破(5)—— Module篇
查看>>
没有什么内存问题,是一行Python代码解决不了的
查看>>
备忘录模式
查看>>
RabbitMQ之集群搭建
查看>>
进程占用量100%问题定位
查看>>
CentOS安装crontab及使用方法
查看>>
Dockerfile构建容器
查看>>
Shell、Xterm、Gnome-Terminal,Konsole简介
查看>>
iptables小脚本
查看>>
configure.ac:9: error: Autoconf version 2.63 or higher is required
查看>>