0

Hey there i'm trying to make a dropdown(v-select) change between two different things to show. In this example code the change is between two console.logs. When i run this code i need to pick one option two times before the method goes into the other statement. Why is this? And how can i fix this?

        <v-select
          v-model="category"
          :items="categories"
          item-text="text"
          item-value="value"
          single-line
          auto
          label="Filter"
          prepend-icon="search"
          @change="a();"
          >
        </v-select>


export default {
  data (){
    return {
      category: null,
      categories: [
        {
          value: 1,
          text: 'Arbete',
          selected: true
        },
        {  
          value: 2,
          text: 'Arbetare',
          selected: false
        }
      ]
     }

      },
      methods: {
        a (){

          if(this.category == 1){

           console.log("work  " + this.category)

        }else{
          console.log("labour  "+ this.category)
        }

      }
  }

1 Answer 1

1

use $nextTick

methods: {
     a() {
         this.$nextTick(() => {
             if (this.category == 1) {
                 console.log("work  " + this.category)
             } else {
                 console.log("labour  " + this.category)
             }
         })
     },
  }
Sign up to request clarification or add additional context in comments.

1 Comment

This works! Thanks alot! I guess i need to read more on the nextTick function!

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.