Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

101
Views
VUE3 - VUEX v-modelo en un objeto

Estoy usando la API de composición de Vue3 y me gustaría almacenar algunos parámetros de búsqueda en mi tienda.

Mi estado:

 const state = () => ({ selection: { selected_cabins: "M", flight_type: "round", adults: 1, children: 0, infants: 0, pets: 0, fly_from: "", fly_to: "", start_date: "", return_date: "", }, });

Estoy tratando de usarlo así:

 <q-select borderless :options="flightType" v-model="selection.flight_type" option-value="value" emit-value map-options />

Propiedad calculada:

 const selection = computed({ get() { return store.state.flights.selection; }, set(val) { store.commit("flights/SET_SELECTION", val); }, });

Pero sigo recibiendo el error de que no puedo mutar el estado fuera de una mutation .

Si divido el objeto ( selections ) en sus propiedades, puedo hacer que funcione, pero eso es realmente detallado. ¿Hay alguna forma de hacer lo anterior con un objeto como lo tengo?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

En v-model , está accediendo al valor de estado anidado que muta ese estado, la sintaxis correcta debería ser como:

 v-model="flight_type"

y en el setter esparcir el estado con propiedad modificada:

 const flight_type = computed({ get() { return store.state.flights.selection.flight_type; }, set(val) { store.commit("flights/SET_SELECTION", {...store.state.flights.selection,flight_type:val); }, });
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!