基于axiox的json-serve用法

基于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": "古遗址"
    }
  ]
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值