When fetching data from Laravel, I use the following response:
$unserialize = unserialize($import->field_names);
return response()->json( $unserialize, 200 ) ;
On Vue JS, I can view the response using:
console.log(response);
The data is displayed in an array format (Check the red arrow mark):
https://i.sstatic.net/qh9Ik.png
I have an empty options
array property defined as follows:
options : []
To add object data to this array with a key value and text, where the value will be each item of the response data, I am using the following code snippet:
response.data.forEach((item, index) => {
this.options.push({
value: item,
text: index
});
});
However, when I console log
console.log(this.options);
I do not see an array of objects in the options property. Instead, I see this:
https://i.sstatic.net/eP3bg.png
Can you explain why? I expect the options should store items like this:
options: [
{ value: null, text: 'Please select some item' },
{ value: 'a', text: 'This is First option' },
{ value: 'b', text: 'Default Selected Option' },
{ value: 'c', text: 'This is another option' },
{ value: 'd', text: 'This one is disabled', disabled: true },
]
Update:
Console.log(response);