1

I am using vue-multiselect to display a multi select dropdown list on UI in vue js. It is present in component section of vue extension by browser, CSS is also present in inspect element, but multiselect dropdown is not getting rendered on the UI. Below is my html and js code, and there is no error in console.

HTML code

  <multiselect
    v-model="pincodeone"
    tag-placeholder="Add this as new tag"
    tag-position="bottom"
    placeholder="Enter the pincode(s)"
    label="name"
    :options="options"
    :multiple="true"
    :taggable="true"
    @tag="PincodeTag"
    @remove="RemoveTag"
  ></multiselect>

Js code

import Multiselect from 'vue-multiselect';
import 'vue-multiselect/dist/vue-multiselect.min.css';

export default {
  name: "test",
  components: { Multiselect },
  props: [],
  data() {
    return { options: [], pincodeone: [], pincodetwo: [] };
  },
  methods: {
    PincodeTag(newTag) {
      const tag = { name: newTag };
      this.options.push(tag);
      this.pincodeone.push(tag);
      this.pincodetwo.push(newTag);
    },
  RemoveTag({ name }) {
    const index = this.pincodetwo.indexOf(name);
    if (index > -1) {
      this.pincodetwo.splice(index, 1);
      this.options.splice(index, 1);
    }
  },
}; }}}}

package.json file
"vue-multiselect": "^2.1.6",

1 Answer 1

0

This is the error I get in console running your code

[Vue warn]: Property or method "RemoveTag" is not defined on the instance but referenced during render.

The problem is that your RemoveTag method is outside of the methods object. Your entire methods object should be like this:

methods: {
    PincodeTag(newTag) {
      const tag = { name: newTag };
      this.options.push(tag);
      this.pincodeone.push(tag);
      this.pincodetwo.push(newTag);
    },
    RemoveTag({ name }) {
      const index = this.pincodetwo.indexOf(name);
      if (index > -1) {
        this.pincodetwo.splice(index, 1);
      }
    }
  }
Sign up to request clarification or add additional context in comments.

4 Comments

Actually, RemoveTag is inside methods only, but while posting question, I made mistake, updated code now. But it is not the issue.
Your updated code is still not perfect, containing extra brackets, }; }}}} and giving syntax errors... but assuming improper copy and pasting again, your current code is fine. I put it in a codesandbox and it renders successfully. You may have an error somewhere else in your app not shown causing the UI to not render.
thanks @yoduh. My page has lots of other components, all were working fine last week, and suddenly only this multi select dropdown is not rendering on the UI with the same code. Is there any changes in package ? Still, I didn't get why it is not rendering.
Is any dependency changed ? or is there any version update for any dependent package ? I think, due to version / dependency change only, this is not working

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.