我有一個VUE成分是這樣的:如何在類別點擊組合框時選擇文本? (Vue.JS 2)
<script>
export default{
template: '\
<select class="form-control" v-model="selected" v-on:change="search">\
<option v-for="option in options" v-bind:value="option.id" v-bind:disabled="option.disabled">{{ option.name }}</option>\
</select>',
mounted() {
this.fetchList();
},
data() {
return {
selected: '',
options: [{id: '', name: window.trans.category.select}]
};
},
methods: {
search(e){
window.location = window.BaseUrl + '/search?q=&cat=' + e.target.value;
},
fetchList: function() {
this.$http.post(window.BaseUrl+'/category/list?parent_id=all').then(function (response) {
response.data.forEach(function(item){
this.options.push({id:item.id, name:item.name})
}, this);
});
},
}
};
</script>
類時點擊,我希望得到的類別
的文字在我上面的代碼,我用這個:e.target.value
得到編號選擇和它的作品
但是,我怎樣才能得到文本選擇類別點擊?
我試試這個:e.target.text
,但ID不工作
是否有任何人誰可以幫我?
是不是在變量:''選擇,它使用的是在'V-model'? – Saurabh
@Saurabh,我想採取的文字。沒有價值。如果我'console.log(this.selected)',結果是值 –
嘗試使用'v-bind:value =「option.name」'代替,讓我知道。 – Saurabh