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;