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数据传递方式: