<!DOCTYPE html>
<html>
<head>
<title>vue-resource</title>
<meta charset="utf-8">
</head> <body>
<div id="app">
<input type="button" value="get请求" @click="getInfo">
<input type="button" value="post请求" @click="postInfo">
</div>
</body>
<!-- 基于vue-resource实现get post请求 也可利用axios第三方包实现-->
<script src="https://cdn.staticfile.org/vue/2.6.10/vue.js"></script>
<script src="https://cdn.staticfile.org/vue-resource/1.5.1/vue-resource.js"></script>
<script>
// vue-promise是基于vue的,所以引入CDN库时需要注意顺序,应先引入vue
let vm = new Vue({
el: "#app",
data:{
},
methods:{//vue-resource发送请求是基于promise的
getInfo(){
this.$http.get('https://www.easy-mock.com/mock/5d537a1cf651bc6ff265fb77/example/result/cart.json')
.then(res=>{
console.log(res);
})
},
postInfo(){
this.$http.post('https://www.easy-mock.com/mock/5d537a1cf651bc6ff265fb77/example/upload',{},{
emulateJSON:true//设置这个参数相当于application/x-www-form-urlencoded,由于手动提交请求没有默认表单格式,需要设置发送的数据格式
})
.then(res=>{
console.log(res.body);
})
},
}
});
</script>
</html>

最新文章

  1. python画决策树
  2. 常用Oracle函数记录
  3. Domain Space
  4. JAVA基础学习day14--集合一
  5. winform窗体的关闭与资源的释放
  6. 动态规划(斜率优化):[CEOI2004]锯木厂选址
  7. Caesar cipher
  8. PBOC/EMV 中SDA和DDA简介
  9. nginx slab内存管理
  10. JVM调优总结:分代垃圾回收详述
  11. DotNetCore跨平台~Quartz定时单次任务
  12. SQL Server CPU
  13. LabVIEW(三):定时与触发
  14. 学习笔记之Problem Solving with Algorithms and Data Structures using Python
  15. JDK JRE JVM的区别
  16. etymon word write alb pain high alt increase large agency ag lose weight fat assist out~3
  17. 3D旋转效果
  18. 使用jQuery仿淘宝商城多格焦点图滚动切换效果
  19. 八、curator recipes之选举主节点LeaderSelector
  20. JavaScript学习笔记(一)——JS速览

热门文章

  1. Linux_CentOS 打包压缩和别名管理
  2. 从0开始学爬虫3之xpath的介绍和使用
  3. ASP将Table导出Excel
  4. 保存wave音频流的方法
  5. LeetCode_263. Ugly Number
  6. POJ 2584 T-Shirt Gumbo 二分图的多重匹配
  7. 神啊,看看Log4Net这个东西吧
  8. LeetCode:打印零与奇偶数【1116】
  9. Centos7防火墙关闭和启用iptables操作
  10. R镜像源的切换