axios初学(1)——get、post请求 发送数据

本文介绍了axios作为vue2.0推荐的HTTP库,如何通过npm或cdn引入,以及如何使用axios进行get、post请求来发送数据给PHP。在get请求中,详细解释了如何传递参数,并提到get.html和post.html中直接引入axios.js可能存在的问题。学习方法包括代码记忆和对比学习。
摘要由CSDN通过智能技术生成

vue.js  本身不支持发送ajax,需要 依赖(vue1.0)vue-resource、(vue2.0)axios  jquery(ajax)
vue2.0 不推荐 vue-resource

axios是一个 基于Promise的http请求客户端
用来来发送请求

npm安装
$ npm install axios
bower安装
$ bower install axios
通过cdn
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>

get.html:

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<script src="../js/vue-2.6.10.js"></script>
	<!-- <script src="../js/axios.js"></script> -->
	<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
	<title>发送get请求</title>
	<script type="text/javascript">
		window.onload=function(){
			new Vue({
				el:'#app',
				data:{
					users:{
						name:'',
						age:''
					}
				},
				methods:{
//axios.get 的发送参数有两种,两个ajax请求函数都可实现
sendGetByStr(){
//1.get通过直接发送字符串拼接
axios.get('get.php?name=${this.users.name}&age=${this.user.age}')
.then(function (response) {
	console.log(response.data);
})
.catch(function (error) {
	console.log(error);
});
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值