vue-resource

2018-06-19 18:31:00
admin
原创
385
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="https://cdn.bootcss.com/vue/2.4.2/vue.min.js"></script>
    <script src="https://cdn.bootcss.com/vue-resource/1.5.1/vue-resource.js"></script>
</head>
<style>
    p{
        color: red;
    }
</style>
<body>
    <div id=app>
        <p>{{message}}</p>
        <button v-on:click="getResourceInfo">获取信息</button>
		<button v-on:click="getResourcePostInfo">获取信息(POST)</button>
    </div>

    <script>
        new Vue({ 
            el:"#app",
            data:{
                message:"hell world",
           },
			methods:{
				getResourceInfo:function(){
					this.$http.get('http://www.filltext.com/?rows=1&fname=tom').then(function(response){
    // 响应成功回调
						 console.log(response);
						this.message = response.data[0].fname;
}, function(response){
    // 响应错误回调
});
					
				},
				getResourcePostInfo:function(){
					this.$http.post('http://www.filltext.com/', {
    					rows:1,
						fname:"henry"
   					})
  					.then(function (response) {
    					console.log(response);
						this.message = response.data[0].fname;
  					})
  					.catch(function (error) {
    					console.log(error);
  					});
				}
			}
        })

    </script>
</body>
</html>				
				
文章分类
联系我们
电话: 18902328227
Email: 2689701946@qq.com
QQ: 2689701946
微信: 18902328227
地址: 广州番禺区繁华路
  • 在线客服
  • 关注微信
  • 联系电话
    • 欢迎咨询
    • 欢迎加入QQ群 303257430
  • 公众号:源宝网络
    • 联系电话及微信号 18902328227