material-web icon indicating copy to clipboard operation
material-web copied to clipboard

How to listen to events in Vue 3?

Open shadow-light opened this issue 2 years ago • 1 comments

I can't figure out how to listen to material component custom events in Vue 3.

The following doesn't work:

<mwc-drawer ref='drawer' @MDCDrawer:opened='opened'>

Where as this does:

onMounted(() => {
    drawer.value.addEventListener('MDCDrawer:opened', () => {
        console.log('opened')
    })
})

Is this an issue with Vue 3 or am I not using the material custom elements correctly?

shadow-light avatar Aug 14 '22 12:08 shadow-light

It's probably having to do with the :. I do not know if there is a way to escape an event name in Vue. Maybe you could ask on their GitHub or discord community.

Matix-Media avatar Aug 30 '22 14:08 Matix-Media

Vue 3 cannot listen for mixed case native events (Vue 3 issue #2460).

The response to the issue when it was raised, was that Vue core lowercases event names because for normal events they have to lowercase the first character 'onClick' -> 'click'.

pgbross avatar Dec 05 '22 16:12 pgbross

Shouldn't be an issue in M3 anymore since we don't use : in our event names

asyncLiz avatar Aug 02 '23 02:08 asyncLiz