SN账"> 无法跳转到另一页的问题在使用laravel-Vue-pagination时的解决方法-PHP中文网问答
无法跳转到另一页的问题在使用laravel-Vue-pagination时的解决方法
P粉598140294
P粉598140294 2023-08-28 16:12:34
0
1
537

在一个表格中,数据被显示出来,但是当我点击由Laravel Vue分页提供的页码时,它显示给我相同的页码1。嗯,主要问题是页码没有传递到函数(Composable API)中。

模板表格

SN 账户类型 姓名 店铺名称 地址 联系电话 电子邮件
{{ ++i }} {{ account.account_type }} {{ account.name }} {{ (account.shop_name)?account.shop_name: 'EMPTY'}} {{ account.address }} {{ account.contact_number }} {{ account.email }}

在:data中传递了来自Composable API的数据,在@pagination-change-page中也传递了函数(Composable)。脚本标签

import LaravelVuePagination from 'laravel-vue-pagination'; export default { components: { 'Pagination': LaravelVuePagination }, setup() { } const paginates = ref(10); const { accounts, loading, getAccounts } = accountDetails();//Composables API onMounted(() => { getAccounts({paginate:paginates}); }); return { accounts, loading,getAccounts }; }, };

可组合 API 在这个函数中,我接收了两个参数,这里是Pagination(@pagination-change-page)应该抛出页码的地方!

import { ref } from '@vue/reactivity'; import axios from 'axios'; const accountDetails = () => { const accounts = ref({}); const loading = ref(true); const accountError = ref({}); const getAccounts = async ({page=1,paginate}) => { await axios.get('api/account/getAccounts?page='+page+'paginate='+paginate, { headers: { Authorization: `Bearer ${localStorage.getItem('token')}`, Accept: 'application/json', } }).then((res) => { accounts.value = res.data; loading.value = false; console.log(accounts.value); }).catch((resErr) => { loading.value = false; accountError.value = resErr; }) } return { accounts, loading, accountError, getAccounts } } export default accountDetails;

P粉598140294
P粉598140294

全部回复 (1)
P粉164942791

成功使用Composition API Vue3进行工作
只需从getAccounts中删除paginate参数,并且不要将paginates传递给该函数。

更新的代码

脚本

import LaravelVuePagination from 'laravel-vue-pagination'; export default { components: { 'Pagination': LaravelVuePagination }, setup() { } const { accounts, loading, getAccounts } = accountDetails();//Composables API onMounted(() => { getAccounts(); }); return { accounts, loading,getAccounts }; }, };

可组合的API

import { ref } from '@vue/reactivity'; import axios from 'axios'; const accountDetails = () => { const accounts = ref({}); const loading = ref(true); const accountError = ref({}); const getAccounts = async (page=1) => { await axios.get('api/account/getAccounts?page='+page, { headers: { Authorization: `Bearer ${localStorage.getItem('token')}`, Accept: 'application/json', } }).then((res) => { accounts.value = res.data; loading.value = false; console.log(accounts.value); }).catch((resErr) => { loading.value = false; accountError.value = resErr; }) } return { accounts, loading, accountError, getAccounts } } export default accountDetails;
    最新下载
    更多>
    网站特效
    网站源码
    网站素材
    前端模板
    关于我们 免责声明 Sitemap
    PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!