Git Product home page Git Product logo

Comments (12)

johnleider avatar johnleider commented on May 9, 2024 31

You must call click .native. Implicit events only work on components with that modifier.

https://vuejs.org/v2/guide/migration.html#Listening-for-Native-Events-on-Components-with-v-on-changed

from vuetify.

garyo avatar garyo commented on May 9, 2024 12

It would perhaps be good for the Vuetify docs to mention what events are emitted by each component (@click, @click.native, @input, etc.). It's hard for a user to know which ones to listen for.

from vuetify.

DespertaWeb avatar DespertaWeb commented on May 9, 2024 5

TOTALLY agree with @pdcmoreira it took me 1 full day to figure it out.
The weird thing is that it worked until I did tested with Jest & Vue-test-utils.
Why is that happening?

side note: Vuetify documentation is so poor. When I could choose I'd stay away from Vuetify. There's some basic stuff missing that, after a few years, it's just not fair.

@saikiranpalimpati it just worked for me:

    <v-btn @click.native="addToCart($event)">
      Add
      <v-icon right>fas fa-cart-plus fa-xs</v-icon>
    </v-btn>

from vuetify.

pdcmoreira avatar pdcmoreira commented on May 9, 2024 4

On all components I made in my previous projects that were wrapping native elements, I always proxied the most commonly used native events, like <button @click="$emit('click', $event)">...</button>.
This way, when I was using my custom button, I could just listen to its click event like it was a native element, like this: <favourite-button @click="addToFavourites(item)"></favourite-button>.
It just feels natural. We shouldn't have to think if we're dealing with a native button or a custom one, both should behave the same. At least that's how I design my components.

from vuetify.

mfferreira avatar mfferreira commented on May 9, 2024

I wasn't aware of the change. That fixed it.

from vuetify.

firepick1 avatar firepick1 commented on May 9, 2024

Confusingly, <v-btn> doesn't look like a native HTML component. It looks like a Vue component.
Indeed, <v-list-tile-title> accepts @click as expected. Might we re-open this and lower the priority? Perhaps the expanded v-btn could simply emit a click to a parent div?
I'm happy brainwashing myself with this special case for v-btn in the short term, but longer term, it's an awkard exception to a beautiful framework.

from vuetify.

johnleider avatar johnleider commented on May 9, 2024

I'm not sure what you are asking for? @click.native is a Vue 2 component caveat, not a Vuetify one.

from vuetify.

firepick1 avatar firepick1 commented on May 9, 2024

I think of <button> as a native component. whereas <v-btn> is Vue component. So it would feel natural to use <button @click.native=...>. However the "v-btn" isn't a native HTML element. It is a Vue component. I just recently ran into this kind of oddness in Vue this week before I found Vuetify. https://github.com/firepick/vue-g-row-col/blob/master/src/grid.vue
I had to explicitly emit an event. I imagine something like this could make @click work for v-btn. Not sure though...

from vuetify.

johnleider avatar johnleider commented on May 9, 2024

There are two types of Vue components, regular and functional.

Regular components must either explicitly emit a native event for the developer to catch using the standard @eventtype, or the developer must use @eventType.native. This was a Vue 2.0 change that was announced pretty early on and did differ from how it was handled in 1.0

Functional components can use the regular @eventtype as they are not instances of Vue.

While it may be nice to explicitly emit the click event on the button to save writing .native, once I start there, it will never end where I will be asked to add it.

from vuetify.

firepick1 avatar firepick1 commented on May 9, 2024

Ahhh. OK. Then we shall all learn to add ".native" to Vue thingies when the expected doesn't work. I guess it's more of an issue for Evan. It must have been a painful change for him as well. Thank you.

from vuetify.

Thaina avatar Thaina commented on May 9, 2024

I start using vue just last week and so I am not familiar with vue much. But I felt confused that just switch from div to md-layout make v-on:click not work and need to add .native

It would be more intuitive if all event need to add .native equally. So if I change html tag to see layout, all of event still work. but, well, I see that it would be bloated

I think this should be improved somehow

from vuetify.

saikiranpalimpati avatar saikiranpalimpati commented on May 9, 2024

v-btn(round color='success' v-on:click.native="console.log('foo')") for me even native does not fix this

from vuetify.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.