我正在尝试从 vue-select 获取选定的值,但已经使用了所有方法并搜索了帮助,但这是否可以工作,我也有在页面加载时触发警报
Vue.component('v-select', VueSelect.VueSelect)
new Vue({
el: '#app',
data: {
options: [
{id: 1, label: 'foo'},
{id: 3, label: 'bar'},
{id: 2, label: 'baz'},
],
selected: '',
},
methods: {
runme: function() {
alert(this.selected);
}
}
})
body {
font-family: 'Source Sans Pro', 'Helvetica Neue', Arial, sans-serif;
}
h1 {
font-size: 26px;
font-weight: 600;
color: #2c3e5099;
text-rendering: optimizelegibility;
-moz-osx-font-smoothing: grayscale;
-moz-text-size-adjust: none;
}
#app {
max-width: 30em;
margin: 1em auto;
}
<script src="https://vuejs.org/js/vue.js"></script>
<script src="https://unpkg.com/vue-select@2.4.0/dist/vue-select.js"></script>
<div id="app">
<h1>Vue Select - Using v-model</h1>
<v-select v-model="selected" :on-change="runme" :options="options"></v-select>
</div>