Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
217 views
in Technique[技术] by (71.8m points)

javascript - Vue Duplicate keys detected

I have some problems with migrating my vue app from vuesax to bootstrap. I never worked with bootstrap and Vue, so it's kinda hard to adopt the first day. I a problem like

Duplicate keys detected: '133'.

showing in console, and I have no idea why. I'm using the same scripts as in vuesax but HTML is different. So I have form repeater that looks like:

<b-row v-for="(product_info, index) in form.product_info">
                        <b-col cols="12" class="mb-2" :style="{animation: 'fadeInDown 0.5s'}">

                            <validation-provider #default="{ errors }" name="Country" rules="required">
                                <b-form-group label="Country" label-for="country" :state="errors.length > 0 ? false:null">
                                    <v-select id="country" v-model="product_info.country" :dir="$store.state.appConfig.isRTL ? 'rtl' : 'ltr'" :options="activeCountries" :selectable="option => ! option.value" label="name" />
                                    <b-form-invalid-feedback :state="errors.length > 0 ? false:null">
                                        {{ errors[0] }}
                                    </b-form-invalid-feedback>
                                </b-form-group>
                            </validation-provider>

                            <validation-provider #default="{ errors }" name="Name" rules="required">
                                <b-form-group label="Name" label-for="name" :state="errors.length > 0 ? false:null">
                                    <b-form-input color="success" label-placeholder="Name" v-model="product_info.name" name="name" type="text" />
                                    <b-form-invalid-feedback :state="errors.length > 0 ? false:null">
                                        {{ errors[0] }}
                                    </b-form-invalid-feedback>
                                </b-form-group>
                            </validation-provider>

                            <validation-provider #default="{ errors }" name="Slug" rules="required">
                                <b-form-group label="Slug" label-for="slug" :state="errors.length > 0 ? false:null">
                                    <b-form-input color="success" label-placeholder="Slug" v-model="product_info.slug" name="slug" type="text" />
                                    <b-form-invalid-feedback :state="errors.length > 0 ? false:null">
                                        {{ errors[0] }}
                                    </b-form-invalid-feedback>
                                </b-form-group>
                            </validation-provider>

                            <validation-provider #default="{ errors }" name="Description" rules="required">
                                <b-form-group label="Description" label-for="description" :state="errors.length > 0 ? false:null">
                                    <b-form-textarea v-model="product_info.description" label="Discription" class="md:mt-10 mt-6 mb-0" rows="3" type="text" name="description" />
                                    <b-form-invalid-feedback :state="errors.length > 0 ? false:null">
                                        {{ errors[0] }}
                                    </b-form-invalid-feedback>
                                </b-form-group>
                            </validation-provider>

                            <b-button v-ripple.400="'rgba(113, 102, 240, 0.15)'" variant="outline-primary" pill @click="deleteProductInfo(index)">x</b-button>
                        </b-col>
                    </b-row>
                    <b-button v-ripple.400="'rgba(113, 102, 240, 0.15)'" variant="outline-primary" pill @click="addProductInfo">Add Product Info</b-button>

And this is scripts

This is how I catch countries from backend:

mounted() {
        Countries.activeCountries().then(response => {
            this.activeCountries = response.data.countries
        });
    },

This is data (product_info is form repeater, packages as well but I haven't migrated it yet):

form: {
                sku: '',
                slug: '',
                category: '',
                type: '',
                product_info: [],
                packages: [],
            },

And those are methods for form repeater:

addProductInfo: function () {
            this.form.product_info.push({
                country: '',
                name: '',
                slug: '',
                description: ''
            });
        },
        deleteProductInfo: function (index) {
            this.form.product_info.splice(index, 1);
        },

The error is coming from:

<v-select id="country" v-model="product_info.country" :dir="$store.state.appConfig.isRTL ? 'rtl' : 'ltr'" :options="activeCountries" :selectable="option => ! option.value" label="name" />

And I have no idea what could cause the problem. Any suggestions?

question from:https://stackoverflow.com/questions/65938811/vue-duplicate-keys-detected

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The problem was a duplicate key entry in the database. I had 2 same countries.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...