javascript - How to get the label value of the select component in element-ui?
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-06-12 09:29:43
0
3
1880


1. As shown in the figure: 202 is selected in the drop-down list. The component's change event prints the value (which is what is printed below), but now I just want to get I don’t want to get the value 202 (which is assigned in the label attribute), but I don’t want to get the value printed below. How to solve it? Thank you, I am annoyed by this problem.

曾经蜡笔没有小新
曾经蜡笔没有小新

reply all (3)
阿神

Your selection is rendered cyclically in the form of an array object (non-repeating). So it can be obtained by simply operating the data form,
add@change="changeValue"

Use the Array find method to find the objects in the array using the properties of the object

changeValue(value) { console.log(value); let obj = {}; obj = this.options.find((item)=>{ return item.value === value; }); console.log(obj.label); }
具体demo如下: // html   

// js var Main = { data() { return { options: [{ value: '选项1', label: '黄金糕' }, { value: '选项2', label: '双皮奶' }, { value: '选项3', label: '蚵仔煎' }, { value: '选项4', label: '龙须面' }, { value: '选项5', label: '北京烤鸭' }], value: '' } } } var Ctor = Vue.extend(Main) new Ctor({ methods:{ changeValue(value) { console.log(value); let obj = {}; obj = this.options.find((item)=>{ return item.value === value; }); console.log(obj.label); } } }).$mount('#app')
@import url("//unpkg.com/element-ui@1.3.5/lib/theme-default/index.css");

You can copy it to this address and run it

    曾经蜡笔没有小新

    label(ref="xxx" data="56")

    this.$refs.xxx.getAttribute('data')

      typecho

      You can try to reverse the label and value, thank you~

        Latest Downloads
        More>
        Web Effects
        Website Source Code
        Website Materials
        Front End Template
        About us Disclaimer Sitemap
        php.cn:Public welfare online PHP training,Help PHP learners grow quickly!