我试图id
在使用v-select
. 现在,我很难获得id
将被选中的值。有人可以帮我解决这个问题吗?
我的index.html
文件是 -
<!DOCTYPE html>
<html>
<head>
<title>VueJs | Select2</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
</head>
<body>
<div id="pageContent">
<form method="POST" @submit.prevent="addSection()">
<div class="form-group">
<label for="className">Select Class</label>
<v-select name="className" v-model="className" :options="academicClasses.map(({cname}) => cname)"></v-select>
</div>
<div class="form-group">
<button type="submit" class="btn btn-success save-btn"><i class="fa fa-check"></i> Save</button>
</div>
</form>
</div>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://unpkg.com/vue-select@latest"></script>
</body>
</html>
我的 vujs 脚本是 -
Vue.component('v-select', VueSelect.VueSelect);
var app = new Vue({
el: '#pageContent',
data: {
className: '',
academicClasses: [],
academicClasses: [
{
id: 1,
cname: 'One'
},
{
id: 2,
cname: 'Two'
},
{
id: 3,
cname: 'Three'
},
{
id: 4,
cname: 'Four'
}
],
},
methods: {
addSection(){
alert(this.className);
}
}
})
请您访问JSFiddle
我要解释的内容!请访问 - JsFiddle