繁体   English   中英

在组合框上单击类别时,如何选择文本? (Vue.JS 2)

[英]How can I get text selected when category clicked on combobox ? (Vue.JS 2)

我有一个像这样的Vue组件:

<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以获取ID并运行

但是,如何在单击类别时如何选择文本?

我尝试这样: e.target.text ,但是id不起作用

有谁可以帮助我吗?

给定您想要的idname ,可以尝试以下操作:

    template: '\
        <select class="form-control" v-on:change="search">\
            <option v-for="option in options" v-bind:value="option.id"  @click="selected=option.name" v-bind:disabled="option.disabled">{{ option.name }}</option>\
        </select>',
    mounted() {
        this.fetchList();
    },

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM