`withModifiers(() => {}, ['right'])` is failed
Vue version
lastest
Link to minimal reproduction
Steps to reproduce
I use withModifiers
at ts(x)
file to achieve the same as @click.right.prevent
, but I found that it's failed
right click the <h1>
, I can see the right result
but used in ts(x)
will be failed
What is expected?
use withModifiers(() => {}, ['right'])
can handle right click method
What is actually happening?
it's failed
System Info
No response
Any additional comments?
No response
it not a bug, you should use onContextmenu
import { defineComponent, h, withModifiers } from 'vue'
export default defineComponent({
name: 'Comp',
setup() {
return () => h('div', {
onContextmenu: withModifiers(() => {
alert(1)
}, ['right', 'prevent']),
}, '哈哈哈')
}
})
it not a bug, you should use
onContextmenu
import { defineComponent, h, withModifiers } from 'vue' export default defineComponent({ name: 'Comp', setup() { return () => h('div', { onContextmenu: withModifiers(() => { alert(1) }, ['right', 'prevent']), }, '哈哈哈') } })
Thx! but maybe onClick
also support?
because withModifiers(, ['right'])
is not actually say that not support for onClick
The logic of template compilation will compile @click
into an onContextmenu
event. In principle, writing in tsx
needs to correspond to the template compilation result. In addition, the onClick
event usually refers to the event when the main mouse button (usually the left button) is clicked, and the right click is usually implemented using onContextmenu
in the browser, because the right click will call out the browser menu, you can only use onContextmenu
to realize yourself the right click event
The logic of template compilation will compile
@click
into anonContextmenu
event. In principle, writing intsx
needs to correspond to the template compilation result. In addition, theonClick
event usually refers to the event when the main mouse button (usually the left button) is clicked, and the right click is usually implemented usingonContextmenu
in the browser, because the right click will call out the browser menu, you can only useonContextmenu
to realize yourself the right click event
Thx! it's helpful for me.