vue 中的 Table 实现新增时的正确页面跳转

实现表格新增数据自动分页

问题描述

组件自带的属性是每页展示十条数据,多了就增加到下一页,即具有分页功能,但是却不能自动进行分页跳转,即当增加第十一条数据的时候,输入框在第二页中,但是此时看到的页面仍然是第一页,也就不能正常进行数据的增加。在这里插入图片描述
在这里插入图片描述

代码实现

首先在table中增加change方法用来实现点击分页和绑定分页器pagination实现自动分页;

<a-table @change="changePage" :pagination = "pagination">

</a-table>

其次在data中定义分页器pagination含有的变量;

data() {
   return {
        //定义分页器,使当新增数据时表格可以自动分页
        pagination: {
            current: 1,
            pageSize: 10,
        },
    };
},

最后在各方法中进行相应代码的实现;

methods: {
	//表单分页(点击下方的页码时触发的方法)
	changePage(pagination){
		this.pagination.current = pagination.current;
	},
	// 显示页面内容
    show(title,editableColumns,data, fatherItem) {
        this.pagination.current = 1;//初始状态显示第一页
    },
    // 添加一条数据
     handleAdd() {
         //判断新增时的数据应该显示在第几页,进而进行正确的页面跳转
         this.pagination.current = Math.ceil(this.cacheData.length / 10);//返回值为大于等于其数字参数的最小整数。
     },
}
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
实现产品列表当前行和产品按钮的详情页,可以使用 Vue Router 的编程式导航。具体步骤如下: 1. 在产品列表,为每一行设置点击事件,绑定一个方法。例如: ``` <template> <div> <table> <tbody> <tr v-for="product in products" :key="product.id" @click="goDetail(product.id)"> <td>{{ product.name }}</td> <td>{{ product.price }}</td> </tr> </tbody> </table> <button @click="goNewProduct()">产品</button> </div> </template> <script> export default { data() { return { products: [ { id: 1, name: '产品1', price: 100 }, { id: 2, name: '产品2', price: 200 }, { id: 3, name: '产品3', price: 300 } ] } }, methods: { goDetail(id) { this.$router.push({ name: 'ProductDetail', params: { id }}) }, goNewProduct() { this.$router.push({ name: 'NewProduct'}) } } } </script> ``` 在上面的代码,我们为每一行设置了点击事件 `goDetail`,并为产品按钮设置了点击事件 `goNewProduct`。 2. 在路由配置,定义产品详情页的路由和产品页的路由。例如: ``` const routes = [ { path: '/', component: Home }, { path: '/product/:id', name: 'ProductDetail', component: ProductDetail }, { path: '/product/new', name: 'NewProduct', component: NewProduct } ] ``` 其,`:id` 表示动态路由参数,可以通过 `$route.params.id` 在产品详情页获取当前行的 id。 希望这些步骤可以帮助您实现产品列表当前行和产品按钮的详情页。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值