zwl1619
zwl1619

Reputation: 4232

How to send an ajax request when an item is selected in a "Select" of vuejs via vue-resource?

How to send an ajax request when an item is selected in a "Select" of vuejs via vue-resource?

demo: https://jsfiddle.net/xoyhdaxy/

<div class="container" id="app">
    <select v-model="selected">
        <option v-for="option in options" v-bind:value="option.value">
            {{ option.text }}
        </option>
    </select>
    <span>Selected: {{ selected }}</span>
</div>

   new Vue({
        el: '#app',
        data: {
            selected: '1',
            options: [
                { text: 'One', value: '1' },
                { text: 'Two', value: '2' },
                { text: 'Three', value: '3' }
            ]
        }
    });

For example:

When the item "two" is selected,an ajax request is triggered with the value "2" via vue-resource,how to write the code?

Upvotes: 0

Views: 374

Answers (1)

Alex
Alex

Reputation: 255

You can 'watch' this property

watch: {
  search : function(value) {
    // your code
  }
}

jsfiddle

Upvotes: 0

Related Questions