Element – UI paging deletes the last item of data to return to the previous page

Method one:

delSubmit() {
      this.$api
        .delete({
          url: `/contractParam/delect/The ${this.delId}`.headers: { "Content-Type": "application/json; charset=UTF-8" },
        })
        .then((e) = > {
          if (e.data.code == 200) {
            this.$message({
              message: "Delete successful!".type: "success"});/ / = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
            let totalPage = Math.ceil((this.pageJson.total - 1) / this.pageJson.limit); / / the total number of pages
            let currentPage =
              this.pageJson.page > totalPage ? totalPage : this.pageJson.page;
            this.pageJson.page = currentPage < 1 ? 1 : currentPage;
            / / = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
            this.query(this.pageJson.page);
          }
        })
        .finally(() = > {
          this.delVisit = false;
        });
    },
Copy the code

Method 2:

if (
  this.pageJson.total - 1= = (this.pageJson.page - 1) * this.pageJson.limit &&
  this.pageJson.page ! =1
) {
  this.pageJson.page--;
}
this.query(this.pageJson.page);
Copy the code

Several ways to determine whether an object is empty

  1. Convert the JSON object to a JSON string and determine if the string is “{}”
var data = {};
var b = (JSON.stringify(data) == "{}");
alert(b);//true
Copy the code
  1. Use ES6’s object.keys () method
var data = {};
var arr = Object.keys(data);
alert(arr.length == 0);//true
Copy the code
  1. Object. GetOwnPropertyNames () method

This method uses the getOwnPropertyNames method of an Object Object, retrieves the property names of the Object, stores them in an array, and returns an array Object. We can check whether the Object is empty by checking the length of the array

var data = {};
var arr = Object.getOwnPropertyNames(data);
alert(arr.length == 0);//true
Copy the code

How to make some globally applicable data public

  1. Create a JS file in the utils folder to expose your data

  1. Introduce it where you need it, just use it