基于axiox的json-serve用法
查数据
let path = `http://localhost:3000/school`;
this.$axios.get(path).then((res) => {
console.log(res);
this.storedata = res.data;
this.data = utils.getAllTree(this.storedata)
})
增加数据
let path = `http://localhost:3000/tree`;
let params = {
"id": '111', "pid": '7', "name": '夏商周遗址', "declare": '夏商周遗址'
}
this.$axios.post(path, params).then((res) => {
console.log(res);
this.storedata = res.data;
this.data = utils.getAllTree(this.storedata)
})
删除数据
let path = `http://localhost:3000/tree/111`;
let params = {
"id": '111', "pid": '7', "name": '夏商周遗址', "declare": '夏商周遗址'
}
this.$axios.delete(path).then((res) => {
console.log(res);
this.storedata = res.data;
this.data = utils.getAllTree(this.storedata)
})
更新数据
this.axios({
method:"patch",
url:"http://localhost:3000/tree/1",
data:{name:"脐橙"}
})
测试数据
{
"school": {
"id": "111",
"pid": "7",
"name": "夏商周遗址",
"declare": "夏商周遗址"
},
"tree": [
{
"id": "2",
"pid": "1",
"name": "文化资源类型",
"declare": "文化资源类型"
},
{
"id": "3",
"pid": "2",
"name": "世界文化遗产",
"declare": "世界文化遗产"
},
{
"id": "4",
"pid": "3",
"name": "平遥古城",
"declare": "平遥古城"
},
{
"id": "5",
"pid": "3",
"name": "云冈石窟",
"declare": "云冈石窟"
},
{
"id": "6",
"pid": "3",
"name": "五台山寺庙",
"declare": "五台山寺庙"
},
{
"id": "1",
"pid": "0",
"name": "字典项",
"declare": "字典项"
},
{
"id": "8",
"pid": "7",
"name": "旧石器时代遗址",
"declare": "旧石器时代遗址"
},
{
"id": "9",
"pid": "7",
"name": "新石器时代遗址",
"declare": "新石器时代遗址"
},
{
"id": "10",
"pid": "7",
"name": "夏商周遗址",
"declare": "夏商周遗址"
},
{
"id": "7",
"pid": "4",
"name": "古遗址",
"declare": "古遗址"
}
]
}