1

Hi I'm using this modified wrapper to handle a multiple select for vue js. I'm trying to change value of this inside vue component. Here is my code.

<select2-multiple :options="car_options" v-model="input.classification">
       <option disabled value="0">Select one</option>
</select2-multiple>

And this is my vue script,

var vm = new Vue({
    el: '#el',
    delimiters: ["[[", "]]"],
    data: {
        input: {
            classification: []
        },
    },
    created: function () {
        var vm = this;
        vm.car_options = [
            {id: "Bubble car", text: 'Bubble car'},
            {id: "diesel", text: 'Diesel'},
            {id: "electric", text: 'Electric'},
            {id: "electric_diesel", text: 'Electric/Diesel'},
            {id: "electric_gasoline", text: 'Electric/Gasoline'},
            {id: "ethanol", text: 'Ethanol'},
            {id: "gasoline", text: 'Gasoline'},
            {id: "hydrogene", text: 'Hydrogene'},
            {id: "lpg", text: 'Liquified petroleum gas (LPG)'},
            {id: "other", text: 'Other'},
        ];
        vm.input.classification = ["Bubble car"];
    }
});

What I want's to do is when multi select appears Bubble car should be automatically selected. It would be great if someone can help. Multi select is working properly and values also are appearing. So I think the issue is in here,

vm.input.classification = ["Bubble car"];

No error message displayed.

2 Answers 2

2

Seems to be working fine for me - JsFiddle

vm.input.classification = [vm.car_options[0].id]
Sign up to request clarification or add additional context in comments.

Comments

0

You need just adding the selected id in the data{} object like that:

selected: ["Bubble car"]

Here is your solution : JsFiddle

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.