Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dropdown functions not worked after refresh page in Vue js 2 #5611

Closed
mrzslr opened this issue Jul 30, 2017 · 1 comment
Closed

Dropdown functions not worked after refresh page in Vue js 2 #5611

mrzslr opened this issue Jul 30, 2017 · 1 comment

Comments

@mrzslr
Copy link

mrzslr commented Jul 30, 2017

hi there. I try to use Semantic UI search dropdown in my own project that I wrote by VueJS 2.
for the first time, I open the create route and everything is ok and the functions are written in mounted function in worked.
but when I refresh the page functions are not works and dropdown default text are disappeared or lost the style.
where is the mistake or problem? any idea?

create.vue - mounted function

mounted(){
$('.ui.search.dropdown')
	.dropdown({
	allowCategorySelection: true
   });
}

template code

<div class="field">
	<select class="ui search dropdown" v-model="form.category">
	     <option value="">Category</option>
	     <option v-for="category in categories" v-bind:value="category.id">{{category.title}}</option>
	</select>
</div>
@vinayakkulkarni
Copy link
Member

Vue.component('dropdown', {
  template: `<div class="ui selection dropdown">
  <input type="hidden" :value="value" @change="updateDropdown">
  <i class="dropdown icon"></i>
  <div class="default text">{{defaultText}}</div>
  <div class="menu">
    <div v-for="item in items" class="item" :data-value="item.id">{{ item.name }}</div>
  </div>
</div>`,
  props: ['items', 'value', 'defaultText'],
  watch: {
    value: function (val, oldVal) {
      if(val == null) {
        $(this.$el).dropdown('clear');
      }
    },
    items: function (val, oldVal) {
      $(this.$el).dropdown('refresh');
    }
  },
  mounted() {
    $(this.$el).dropdown();
  },
  methods: {
    updateDropdown() {
      let id_value = $(this.$el).find('input').val();
      id_value = (id_value === "" || id_value === null) ? '' : id_value;
      this.$emit('input', id_value);
      this.$emit('valuechanged');
    }
  }
});

Assuming your item object has id and name

also, for any usage related questions, ping us on: Gitter Channel or Semantic-UI Discord server

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants