1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > Vue.js 原生axios实现get和post请求 PostMan请求数据格式

Vue.js 原生axios实现get和post请求 PostMan请求数据格式

时间:2019-03-07 04:19:12

相关推荐

Vue.js 原生axios实现get和post请求  PostMan请求数据格式

1.Vue.js 中 实现原生axios中的GET&POST请求

1。导入axios库

<script src="/axios/dist/axios.min.js"></script>

2。实现GET请求 (/api/joke/list?[num=?])测试网址

<script>document.getElementById("get").onclick = function() {axios.get("/api/joke/list?num=6").then(res => {console.log(res)}).catch(err => {console.error(err);})console.log("object");}

返回结果如下:

3。实现POST请求 (/api/user/reg) 测试网址

document.querySelector("#post").onclick = function() {axios.post("/api/user/reg", {username: "张三"}).then(function(response) {console.log(response);}).catch(function(error) {alert(error)})}

返回结果如下:

2.PostMan请求网址测试:

1.这里需要注意的是,传入的数据是json数据,而不是表单数据,否则会提示提交的数据不正确

2.应该使用正确的json数据传递方式:

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。