• Ajax
  • Ant design
  • Axios-Fetch
  • Avue
  • Browser
  • Canvas
  • CSS
  • Dos-bat
  • Dva
  • Dedecms
  • Echart
  • ElementUI
  • Editors
  • Git
  • GeoServer
  • GIS
  • H5
  • Jquery
  • Java安卓
  • Json
  • Javascript
  • Leaflet
  • Linux
  • Life-Info
  • Mock
  • MongoDB
  • Network
  • NodeJS
  • NPM
  • React
  • 设计运营
  • SEO
  • SVG
  • TypeScript
  • Tools
  • umi
  • uni-APP
  • Vant
  • Vue
  • Windows
  • webpack
  • 位置:OC中文网 > 其他 > Axios-Fetch >

    vue配合Axios的增删改查demo

    来源:GIS示例网 时间:08-13

     分页:

    1.  <pagination @getList="getPages" :count="count"></pagination> 
    2.  
    3.  
    4.  import Pagination from "@/components/common/pagination"; 
    5.  
    6.  
    7.      filters: { 
    8.         search: "", 
    9.         searchFields: "groupName", 
    10.         page: 1, 
    11.         pageSize: 10, 
    12.       }, 
    13.       count: 0,  
    14.  
    15.  
    16.  components: { 
    17.     Pagination, 
    18.   }, 
    19.  
    20.  
    21. getList() { 
    22.       this.$request(this.$api.groupList, this.filters, "GET") 
    23.         .then((res) => { 
    24.           console.log(res); 
    25.           if (res.data.code == 200) { 
    26.             this.count=res.data.data.total; 
    27.             this.listData.rows = res.data.data.rows; 
    28.           } else { 
    29.             console.log("获取失败"); 
    30.           } 
    31.         }) 
    32.     },   
    33.     getPages(obj) { 
    34.       if (obj.mode === "pageSize") { 
    35.         this.filters.pageSize = obj.pageSize; 
    36.       } else { 
    37.         this.filters.page = obj.currentPage; 
    38.       } 
    39.       this.getList(); 
    40.     }, 

     

    GET方法

    1. getGroupData(){ 
    2.    let filter = { 
    3.        page: 1, 
    4.        pageSize: 10, 
    5.    }; 
    6.    this.$request(this.$api.groupList, filter, "GET") 
    7.      .then((res) => { 
    8.        console.log(res); 
    9.        if (res.data.code == 200) { 
    10.          this.$refs.groupTable1.listData=res.data.data; 
    11.        } else { 
    12.          console.log("获取失败"); 
    13.        } 
    14.      }) 
    15.      .catch((e) => { 
    16.        this.$message.error(e); 
    17.      }); 
    18.  }, 

     POST方法

    1. getGroupData(){ 
    2.    let filter = { 
    3.        page: 1, 
    4.        pageSize: 10, 
    5.    }; 
    6.    this.$request(this.$api.groupAdd, filter, "POST") 
    7.      .then((res) => { 
    8.        console.log(res); 
    9.        if (res.data.code == 200) { 
    10.          this.$refs.groupTable1.listData=res.data.data; 
    11.          this.$refs.groupTable1.count=res.data.data.total; 
    12.        } else { 
    13.          console.log("获取失败"); 
    14.        } 
    15.      }) 
    16.      .catch((e) => { 
    17.        this.$message.error(e); 
    18.      }); 
    19.  }, 

    DELETE方法

    1. getGroupData(){ 
    2.    let filter = { 
    3.        page: 1, 
    4.        pageSize: 10, 
    5.    }; 
    6.    this.$request(this.$api.groupList, filter, "DELETE") 
    7.      .then((res) => { 
    8.        console.log(res); 
    9.        if (res.data.code == 200) { 
    10.          this.$refs.groupTable1.listData=res.data.data; 
    11.          this.$refs.groupTable1.count=res.data.data.total; 
    12.        } else { 
    13.          console.log("获取失败"); 
    14.        } 
    15.      }) 
    16.      .catch((e) => { 
    17.        this.$message.error(e); 
    18.      }); 
    19.  },