6

HTML

<v-select
  v-model="selectedBank"
  :items="items"
  item-text="bankName"
  label="Select a bank"
  persistent-hint
  return-object
  single-line
>
</v-select>

<v-btn 
  round 
  block 
  color="blue darken-3" 
  dark 
  large 
  @click="directToBank(items.bankName)"
>
  CONTINUE
</v-btn>

JS

async directToBank(bankID) {
  console.log("Came into directtobank", this.selectedBank.bankName)
}

How can I get the selected value of v-select upon clicking on the button ? . .

3
  • Get the value of selectedBank Commented Aug 22, 2018 at 8:47
  • Cannot read property 'selectedBank' of null @kgbph Commented Aug 22, 2018 at 8:50
  • Change this.selectedBank.bankName to x.selectedBank where x is your Vue object declaration. Commented Aug 22, 2018 at 8:53

3 Answers 3

8

If you are refering to you can continue reading.

Let's take this example (codepen):

new Vue({
  el: '#app',
  data: () => ({
    items: [
      {value: '1', bankName: 'Bank1'},
      {value: '2', bankName: 'Bank2'},
    ],
    selectedBank: null
  }),
  methods: {
    directToBank() {
      console.log("Label: ", this.selectedBank.bankName)
      console.log("Value: ", this.selectedBank.value)        
    }
  }
})

If you use other key for value in your items object you need to specify the item-value attribute in your v-select element, else it will use the "value" key by default.

More on v-select component

Sign up to request clarification or add additional context in comments.

1 Comment

Be careful; v-select must have return-object prop as above!
3

When you use return-object, you are bringing selectedBank into data() hence you will only need to call this.selectedBank.something inside your your @click function in the button.

1 Comment

This is great <v-select v-model="selected" item-text="name" :items="tokens" item-value="" return-object></v-select>
1

Getting values from vuetify select is similar to getting the values for an even fired in javascript.

passing the even as a prop and the prop is the value you want

new Vue({
  el: '#app',
  vuetify: new Vuetify(),
  data: {
    items: ['Foo', 'Bar', 'Fizz', 'Buzz'],
  },
  methods: {
    select_value(e) {
      console.log(e)
    }
  }
})
<v-select :items="items" label="Solo field" @change="select_value" solo></v-select>

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.