<!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>
如对本文有疑问, 点击进行留言回复!!
Android 入门第七讲01-数据存储(数据存储概述,文件存储(raw和asserts目录读写,data/data/包名目录读写,sdcard目录读写),SharedPreferences读写)
vue-axios系列:axios拦截器,配置请求头,配置请求参数
Vuejs 针对 安卓低版本 、ios9.x 不兼容 ES6语法导致失效解决方法
网友评论