<script> let app = new Vue({ el:"#app", data:{ //默认页码第一页 num:1, pageInfo:{}, name:"" }, methods:{ queryList(pageNum){ let param = new URLSearchParams(); param.append("pageNum",pageNum); axios.post("/day0530/company/list",param) .then(response=>{ let resp = response.data; this.name = resp.data.name; this.pageInfo = resp.data.pageInfo; //跳转到第几页的页码 this.num = resp.data.pageInfo.pageNum; }) }, add(){ location.href = "/day0530/company/add.jsp" }, remove(id){ axios.get("/day0530/company/remove?id="+id) .then(response=>{ let resp = response.data; if (resp.code===200){ alert("删除成功"); this.queryList(1); }else { alert(resp.msg); } }) }, updatePage(id){ axios.get("/day0530/company/updatePage?id="+id) .then(response=>{ let resp = response.data; if (resp.code===30001){ alert(resp.msg); }else { location.href = "/day0530/company/updatePage?id="+id; } }) }, search(name){ axios.get("/day0530/company/search?name="+name) .then(response=>{ let resp = response.data; if (resp.code===30002){ alert(resp.msg); }else { location.href = "/day0530/company/search?name="+name; } }) } }, created(){ this.queryList(1); } }) </script>
时间: 2024-02-10 18:19:16 浏览: 146
这段代码定义了一个Vue实例,将其挂载到`id`为`app`的元素上。该实例中包含了一些数据属性,如`num`、`pageInfo`和`name`,以及一些方法,如`queryList()`、`add()`、`remove()`、`updatePage()`和`search()`。其中,`queryList()`方法是用来查询分页数据的,`add()`方法是用来跳转到新增页面的,`remove()`方法是用来删除数据的,`updatePage()`方法是用来跳转到修改页面的,`search()`方法是用来根据关键字搜索数据的。
在Vue实例的`created()`生命周期函数中,调用了`queryList()`方法,查询了第一页的数据,并将查询结果赋值给了Vue实例的`num`、`pageInfo`和`name`属性。此后,当用户进行分页、删除、修改或搜索操作时,分别会触发对应的方法,来更新Vue实例中的数据属性,或者跳转到其他页面。
总体来说,这段代码实现了一个简单的分页查询功能,并提供了一些常见的操作,如新增、删除、修改和搜索。
阅读全文