P粉1649427912023-08-29 00:48:39
成功使用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;