vueform / multiselect

Vue 3 multiselect component with single select, multiselect and tagging options (+Tailwind CSS support).
https://vueform.com
MIT License
807 stars 150 forks source link

How can I set default value? #334

Closed HeadStudios closed 1 year ago

HeadStudios commented 1 year ago

Below is my code how do I set 'joker' for example to be default value?

<template>
  <Multiselect
  v-model="value"
  class="custom-multiselect"
  mode="tags"
  :close-on-select="false"
  :options="{
    batman: 'Batman',
    robin: 'Robin',
    joker: 'Joker'
  }"
  @click.native.stop
/>
</template>

<script>
import Multiselect from '@vueform/multiselect'
import axios from 'axios';

export default {
props: ['index', 'resource', 'resourceName', 'resourceId', 'field'],
components: {
      Multiselect,
    },
    data() {
      return {
        value: null,
        options: [
          'Batman',
          'Robin',
          'Joker',
        ]
      }
    },
    mounted() {
    this.value = [{ value: 'Joker', label: 'Joker' }];
  },
    watch: {
    value: {
      handler(newValue) {
        console.log("The value we just got is...");
        console.log(newValue);

        //console.log(this.resource.title);
        Nova.success('We like it like that! The resource id is: ' + this.resource);
      },
      deep: true,
    },
  },
}
</script>

<style src="@vueform/multiselect/themes/default.css"></style>
<style scoped>
.custom-multiselect {
  width: 250px; /* Adjust this value to set the desired width */
}
</style>
yogesh-gohil commented 1 year ago

hey @HeadStudios , you can fix this issue by doing following way hope it will helps you,