Skip to content
Advertisement

v-model is not changing data with switch and select dropdown in vuejs

I’m making a dynamic admin panel with crud generator with the help of laravel and vue.

I have a table where I’m loading data asynchronously from API. There is an is_featured column in my table which I want to be a switch. So that the user can change the value from the table page instead of going to edit page.

To generate my entire table there is a configuration object that contains which fields to show and the type of that field and other metadata. In the configuration object, there is a field named prerender which is responsible to prerender fields that require calling other API or some editable fields like select dropdown or switch.

To make switch and select fields work, I have an empty object named fieldData. When a field with type: boolean and prerender: true is found, my code will initialize a property with field.name as property name in field data and fill it with the corresponding values under that field name

JavaScript

BUT THE SWITCH AND SELECT ARE NOT WORKING HERE

So I need help.

Here’s my entire code for reference

JavaScript

Advertisement

Answer

I guess this is a reactive issue. The value of dict and actually not affecting the feildData dict.

changes –

JavaScript

replace this with

JavaScript

and

JavaScript

I think this will fix the issue.Instead of using = use $set for value assignment.

Codepen – https://codepen.io/Pratik__007/pen/gObGOKx

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement