码迷,mamicode.com
首页 > 其他好文 > 详细

vue-resource 的get和post学习

时间:2017-07-14 13:28:37      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:for   script   val   div   source   return   back   api   turn   

vue-resource 的get和post学习
<
template> <div class="winter"> <button @click="getUser">点我1</button> <button @click="postWq">点我2</button> <div v-for="item in msg"> <p>{{item.id}}</p> <p>{{item.name}}</p> <p>{{item.age}}</p> </div> <p>{{msg2.id}}</p> <p>{{msg2.name}}</p> <p>{{msg2.age}}</p> </div> </template> <script> export default{ name:winter, data() { return{ msg:‘‘, msg2:‘‘ } }, methods:{ getUser(){ this.$http.get("http://localhost:5000/api/values").then((res)=>{ console.log(this.msg=res.body)//请求成功打印数据(数据后台给的) }) .catch((res)=>{alert(1)})//请求失败弹出1 }, postWq () { let ws = {id: 1, name: 你好, age: 20} this.$http.post(http://localhost:5000/api/values, ws).then(a => { console.log(this.msg2 = a.data)//请求成功打印数据1 你好 20 }).catch((e) => { alert(1)//请求失败弹出1 }) } } } </script>

 

vue-resource 的get和post学习

标签:for   script   val   div   source   return   back   api   turn   

原文地址:http://www.cnblogs.com/queenaq/p/7169510.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!