Skip to content
Advertisement

Is there a way to shorten defining v-model data, Vue.js and Laravel

On my edit page of CRUD project, I have a code that fills the form with values of which record is being edited.
I use v-model to define HTML inputs, but the code seems too long.
I get the data from the prop, and fill the v-model.

My code that fills v-model

JavaScript

The way I get the data using prop: props: ['student'] and in blade <student-edit-component :student="{{$student}}">

Defining v-models in script

JavaScript

That fills the value on the form inputs with it’s data.

Is there a way to shorten this code using props or arrays?

Please help me, I’m so new to Vue

Advertisement

Answer

You can change your model of data adding a new layer. For example:

JavaScript

Then in created you can use simple

JavaScript

And in all component replace names by names with currentStudne eg in v-models:

JavaScript

You can also read about Vue.$set

https://v2.vuejs.org/v2/guide/reactivity.html

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