0

I need click a div to pop the options in the event. My code are as followed.

<div class="value" @click.native="onClick">
    <select v-if="mode=='select'" ref="selectNative">
        <option value="volvo">one</option>
        <option value="saab">two</option>
        <option value="mercedes">three</option>
    </select>
</div>

I use Vue get Dom element by ref and bind onClick on div

this.$refs.selectNative.dispatchEvent(new MouseEvent('click', { 'bubbles': false }));

but it doesn't work.

I want to get options when click the div. enter image description here

enter image description here

RichardSleet
  • 373
  • 4
  • 17

2 Answers2

0

You should try MouseEvent instead of simple 'Event'

QaMar ALi
  • 229
  • 2
  • 12
0

Why not add the @click to the <select> and use @click="onClick($event.currentTarget)"?

<div class="value" @click="onClick($refs.selectNative)">
    <select v-if="mode=='select'" ref="selectNative" @click="onClick($event.currentTarget)">
        <option value="volvo">one</option>
        <option value="saab">two</option>
        <option value="mercedes">three</option>
    </select>
</div>
acdcjunior
  • 132,397
  • 37
  • 331
  • 304