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

313
Visualizações
I can't display json with select option (Laravel Vue)

I want to display the value in Options with province_id and province. but in the options it always appears in JSON format. please help me i'm stuck

this my create.js

 changeShippingCountry(country) {
        this.$set(this.form.shipping, 'country', country);

        this.fetchStates(country, (states) => {
            this.$set(this.states, 'shipping', states);
            this.$set(this.form.shipping, 'state', '');
        });
    },

    fetchStates(country, callback) {
        $.ajax({
            method: 'GET',
            url: route('provinces'),
            dataType: "json",
        }).then(callback);
    },

and this billing_detail.blade.php

<input
                        type="text"
                        name="billing[state]"
                        :value="form.billing.state"
                        id="billing-state"
                        class="form-control"
                        v-if="! hasBillingStates"
                        @change="changeBillingState($event.target.value)"
                    >

                    <select
                        name="billing[state]"
                        v-model="form.billing.state"
                        id="billing-state"
                        class="form-control arrow-black"
                        v-else
                    >
                        <option value="">{{ trans('storefront::checkout.please_select') }}</option>

                        <option
                            v-for="(name, code) in states.billing"
                            :value="code"
                            v-text="name"
                        >
                        </option>
                    </select>

this is result in options

enter image description here

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

0

I can't see how your backend data is provided in PHP, but I'm making the assumption here that states.billing is an array of objects, each object with the elements province_id and province in it.

In the vue documentation, you can read that the 2nd arguments you put in between brackets at the front of a v-for loop differ, depending on whether your v-for loops over an array or an object.

If it is an array, the documentation reads:

v-for also supports an optional second argument for the index of the current item.

If it is an object, the documentation reads:

You can also provide a second argument for the property’s name (a.k.a. key)

Considering that you are looping over an array (of objects), you should probably update your v-for loop to something like this:

<option
  v-for="(item, index) in states.billing"
  :value="item.province_id"
  :key="index"
>
  {{ item.province }}
</option>

Note that I'm using the index for the key attribute here. If your province_id is unique, you can also do the following:

<option
  v-for="item in states.billing"
  :value="item.province_id"
  :key="item.province_id"
>
  {{ item.province }}
</option>
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