GET请求
btns[0].onclick = function() {
axios({
method: 'GET',
url: "http://localhost:3000/posts/2"
}).then((response) => {
console.log(response);
})
}
POST请求
btns[1].onclick = function() {
axios({
method: 'POST',
url: "http://localhost:3000/posts",
data: {
title: "这是第三篇文章,菜根谭",
author: "玩野猫"
}
}).then((response) => {
console.log(response);
})
}
PUT请求
btns[2].onclick = function() {
axios({
method: 'PUT',
url: "http://localhost:3000/posts/3",
data: {
title: "朱元璋很好看",
author: "刘伯温"
}
}).then((response) => {
console.log(response);
})
}
DELETE请求
btns[3].onclick = function() {
axios({
method: 'delete',
url: "http://localhost:3000/posts/3",
}).then((response) => {
console.log(response);
})
}