The pagination in Laravel Vue is causing a validation error due to an invalid prop type check failing

Recently, I delved into working with Nuxt.js and decided to install the Laravel-Vue-Pagination plugin. However, I encountered an error message in my console system that reads:

[Vue warn]: Invalid prop: type check failed for prop "data". Expected Object, got Array 

Here is a snippet of my code causing the issue:

getResults (page = 0) {
  this.$axios.$get('mydomain.com/api/Customer/loadCustomers/' + page).then((response) => {
    this.laravelData = response.data
  })
},

Below is how I structured my data:

data () {
return {
  laravelData: {},
  formFields: {},
  search: null,
  editMode: true,
  customerId: null,
  refresh: false
}
}

Here's the HTML code snippet where I use the pagination component:

<pagination :data="laravelData" @pagination-change-page="getResults" />

I made sure to register the components by using this import statement:

import Vue from 'vue'
Vue.component('pagination', require('laravel-vue-pagination'))

Additionally, here is a glimpse of the JSON feedback I received:

{
"success": false,
"total": 6,
"per_page": 10,
"current_page": 0,
"last_page": 1,
"data": [
    {
        "id": "34",
        "customer_name": "Philippe Lesen",
        "customer_company_name": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dfbbb0a7a6bbb6a8beafb09fb2beb6b3b6b1beabb0adf1bcb0b2">[email protected]</a>",
        "customer_email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="771a02040e151214160716371a161e1b1e191603180559191203">[email protected]</a>",
        "customer_phone": "+4382251059",
        "customer_fax": "+1 (223) 134-7141",
        "customer_mobile": "+4382251059",
        "customer_website": "https://www.qusopywode.org.au",
        "customer_type": "2",
        "billing_address": "Cupiditate alias asp",
        "billing_city": "Delectus reprehende",
        "billing_state": "In velit illo ut vol",
        "billing_zip": "73660",
        "billing_country": "TH",
        "shippingaddr_id": null,
        "currency": "EUR",
        "sales_representative": null,
        "payment_condition": null,
        "payment_method": null,
        "tax_preference": "1",
        "invoice_notification": "1",
        "note": null,
        "status": null
     }
]
 }

Answer №1

The problem was resolved by implementing this.laravelData = response

Answer №2

The issue has been resolved, thanks to your efforts.

In your code, you initially declare the variable laravelData as an object:

 laravelData: {},

However, later on, you assign it to an array:

this.laravelData = response.data

resulting in a potential mismatch of data types.

"data": [

To rectify this, consider declaring laravalData as an array instead.

 laravelData: [],

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue with the positioning of the datepicker is not functioning properly

I'm currently facing an issue with the position of a date picker plugin from jquery. The search box on my website allows users to select a range of dates using the date picker, but when enabled, the date picker appears at the bottom left corner of the ...

Filter the array while maintaining its current structure

I'm struggling to create an array filter that can handle exact and partial data within a nested array structure. The challenge is maintaining the integrity of the top-level structure while filtering based on data in the second layer. Here's an ex ...

Implementing a loading animation effect using AJAX that requires a loop delay and sleep functionality

My jquery ui dialog is loaded via ajax with a partial view from the server. Initially, the dialog opens as a dialog-ajax-loader and then animates/grows to fit the content once the call returns. The issue arises when the dialog content gets cached or the a ...

Is it possible for CSS to prevent the insertion of spaces?

When filling out a form, I am able to insert spaces in inputs but not in the textarea (which is necessary). Interestingly, inserting spaces in the textarea works flawlessly. <form action="/#wpcf7-f519-o1" method="post" class="wpcf7-form" enctype="mu ...

Leveraging split and map functions within JSX code

const array = ['name', 'contact number'] const Application = () => ( <div style={styles}> Unable to display Add name & contact, encountering issues with splitting the array). </div> ); I'm facing difficul ...

Run a PHP statement when a JavaScript condition evaluates to true

I am attempting to run a php statement if my javascript condition is true. Here is the code snippet that I have written: <input id="checkbox1" type="checkbox"> MSI<br></input> <script> $(document).ready(function(){ $(&apos ...

Is it possible for PHP to use the set cookie function to replace the cookie value set by JQuery cookie?

I'm facing an issue where I want a single cookie to be set and its value updated by PHP when a user logs in. However, currently it seems to just create a new separate cookie each time. Below is the code snippet where I am trying to set the cookie valu ...

Testing a React component's function within the confines of a Redux Provider component

My current challenge involves unit-testing a React component called TodoList. This component essentially maps through items and displays them in the render method. These items, of type TodoItem, are retrieved from the Redux store using MapStateToProps. Be ...

I am facing an issue where the URL generated in the Controller in Laravel is not functioning properly when

After escaping the single quote, I included a URL link inside the Controller and passed it through json_encode. However, when I clicked on the URL link, it did not work and showed this: The URL appeared like this: http://localhost/BSProject/public/%7B% ...

"Enhancing User Experience with Hover States in Nested React Menus

I have created a nested menu in the following code. My goal is to dynamically add a selected class name to the Nav.Item element when hovering, and remove it only when another Nav.Item is hovered over. I was able to achieve this using the onMouseOver event. ...

The efficiency of a for loop in Javascript can be influenced by the way the loop

I experimented with three different for loop cases in JavaScript, each performing a seemingly useless action 1000000000 times. Surprisingly, the speed of these codes varied from one another. Initially, I suspected that the difference in performance could ...

Tips for writing unit tests for components using vitest in the latest version of Nuxt

I've been working on transitioning from Vue 3 to Nuxt 3. I've successfully written unit tests for my components using vitest in my Vue app, however, when running the same tests in the Nuxt app, I encounter the following error: Error: Failed to ...

I am having difficulty accessing the dataset on my flashcard while working with React/Next JS

I'm currently developing a Flashcard app that focuses on English and Japanese vocabulary, including a simple matching game. My goal is to link the two cards using a dataset value in order to determine if they match or not. When I click on a flashcar ...

The functionality to move forward and backward in Modal Bootsrap seems to be malfunctioning

I am in need of assistance as I have encountered a major issue that has halted my work progress for several days. My goal is to implement a feature that allows users to navigate between different days both forwards and backwards. While the functionality it ...

How to Link an Object's Value to a Checkbox in Vue

My goal is to populate the array selectedParks with the value of each item. However, I am facing an issue where the value is always set to the string "item" instead of the actual value of the Park Object. Here is the code snippet: <ul class="list- ...

Dynamic Search Functionality using Ajax and JavaScript

function fetchData(str) { if (str.length == 0) { var target = document.querySelectorAll("#delete"); return; } else { var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (this.readyState == 4 && ...

Cross-Origin Resource Sharing (CORS) verification for WebSocket connections

I am currently utilizing expressjs and have implemented cors validation to allow all origins. const options = { origin: ['*'], credentials: true, exposedHeaders: false, preflightContinue: false, optionsSuccessStatus: 204, methods: [&a ...

The event listener for the hardware back button in $ionicPlatform is being triggered repeatedly

Encountering a glitch with the back button being triggered multiple times. While I'm in the "messages" $state, everything functions normally when hitting the back button. var messageIsClosed = true; $ionicPlatform.onHardwareBackButton(function(even ...

The Controller is failing to pass JSON Data to the AJAX Call

When trying to access JSON data in the Controller, it is not being retrieved in the Success function and instead showing an error message "Failed to load resource: the server responded with a status of 406 (Not Acceptable)" or executing the Error function. ...

Restore the initial content of the div element

Currently, I am utilizing the .hide() and .show() functions to toggle the visibility of my page contents. Additionally, I am using the .HTML() function to change the elements inside a specific div. $('#wrap').html(' <span id="t-image"> ...