Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

147
Visualizações
Vue: Why does computed property require .value in v-model directive when declared in a store but not when declared in the component

When I move a computed prop from my component to the store, I have to use .value in the v-model directive.

The two quasar select lists below are both working. They both display the state from the store, with the first one accessing the state from a computed property in the store and the second one accessing the state from a computed property in the component.

Both computed props are essentially the same implementation, why do I have to use .value in the first one's v-model directive?

    <q-select
        outlined
        v-model="store.warehouse.currentDepotCode.value" 
        :options="store.warehouse.getDepotSelectList()"
        emit-value
        map-options
        label="Select a Depot"
        class="q-ma-md"
    />
    
    <q-select
        outlined
        v-model="currentDepotCode" 
        :options="store.warehouse.getDepotSelectList()"
        emit-value
        map-options
        label="Select a Depot"
        class="q-ma-md"
    />

  setup() {
    const store = inject("store");

    const currentDepotCode = computed({
        get(){
            return store.warehouse.state.currentDepot;
        },
        set(depotCode){
            store.warehouse.setCurrentDepot(depotCode);
        }
    });
    
    return {
        store,
        currentDepotCode,  
    };

store/index.js


    const state = reactive({
        depots,
        currentDepot: 'VIC',
    });

    const currentDepotCode = computed({
        get(){
            return state.currentDepot;
        },
        set(depotCode){
            state.currentDepot = depotCode;
        }
    });

    export default {
        state: readonly(state),
        ...methods,
        ...getters,
        currentDepotCode,
    };

(I am using a computed prop because the select component will appear on a number of pages so I want to use a setter function and I dont want to repeat the computed prop on every page, so its going in the store. Happy to have comments on this set up too).

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

i think because q-select options is an array of objects, store.warehouse.getDepotSelectList() the real value of each element

ex: [{ key: 1, value: 'first' }, { key: 2, value: 'second' }]

because in documentation it's using value directly https://quasar.dev/vue-components/select

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda