首页 > Web开发 > 详细

vue-resource请求,类似ajax

时间:2020-01-17 23:02:28      阅读:63      评论:0      收藏:0      [点我收藏+]

 

<template>
	<div>
		<div>vue-resource请求,类似ajax</div>
		<div>----------------------------</div>
	</div>
</template>
<script>
	export default{
		data(){
			return{

			}
		},
		mounted(){
			//get请求   ‘/someUrl‘ 是后台地址的数据接口如:someUrl.php 等等
			this.$http.get(‘/someUrl‘).then(response => {  //获取响应数据
				// get body data
				console.log(response.body);   //输出响应数据
		    }, response => {
		    	//error callback
		    });

		    //post请求     ‘/someUrl‘ 是后台地址的数据接口如:someUrl.php 等等
		    // {foo: ‘bar‘}  给后台发送一些数据
	    	this.$http.post(‘/someUrl‘, {foo: ‘bar‘}).then(response => {  //获取响应数据
	    		// get body data
	    		console.log(response.body);   //输出响应数据
	        }, response => {
	        	//error callback  请求失败执行的回调函数
	        });


    	    //get请求     ‘/someUrl‘ 是后台地址的数据接口如:someUrl.php 等等
    	    // {foo: ‘bar‘}  给后台发送一些数据
        	this.$http.get(‘/someUrl‘, {params: {foo: ‘bar‘}, headers:{‘X-Custom‘: ‘...‘}} ).then(response => {  //获取响应数据
        		// success callback  请求成功的回调函数
            }, response => {
            	//error callback  请求失败的回调函数
            });
		}
	}
</script>

  

vue-resource请求,类似ajax

原文:https://www.cnblogs.com/Knowledge-is-infinite/p/12207445.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!