5 ms·
The devtools (Jetbrains Webstorm for instance) automatically detect that `increment` refers to the method. So it actually works quite well in practice. And you
by frenchman99 7y ago
The devtools (Jetbrains Webstorm for instance) automatically detect that `increment` refers to the method. So it actually works quite well in practice. And you can use @click="increment(any, args, here)" if you want. The syntax @click="increment" is just syntactic sugar for @click="increment($event)", I think.
- cremp 7y agoI think what he means is why not use ++ in the click handler. We don't need a function to increment something. Standard HTML, onclick="var++"
- ry4nolson 7y agoNo, I think he's referring to the fact that the function increment is called by interpreting the string "increment".
- aliveupstairs 7y agoyou can do exactly that, they just wanted to showcase the methods option. often you would switch true to false doing: `@click="isSomething = !isSomething"`
- cooperadymas 7y agoExactly this. Template directives support a lot of JS functionality (while not encouraging it, like JSX does). That said, except in rare, extremely simple cases I still prefer wrapping that logic in a computed property or method, as it will inevitably grow more complex later.
- lima 7y agoStill makes it harder to refactor, use code analysis/indexing tools and so on.
- cooperadymas 7y agoSince the way you build a vuejs application encourages breaking your code into small, mostly self contained, focused components this is rarely a real problem in my experience. Tooling also seems to deal with it just fine.
- mpolichette 7y agoIt's cool if tooling helps with this. Thats important. I'm mixed on vue because of the string bindings. I really like to know where my variables are coming from and really hate when two dependent uses but not actually the same thing... That said, I'm happy to re-evaluate my stance... so what does it mean to be "the same thing"? I suppose in the past, I would say that the compiler thinks the things are the same, and it would be easy to change either: 1. If it is a value, I can set/change it in a single spot 2. If it's a token, it is easy to detect and change everywhere, and tooling will help my avoid misses. That said, in React, if you were to mess up a 'token', the runtime would be very upset and it would be hard to have something like `onClick={incremant}` (note the a). Tools would make it super easy to spot. What does vue do if you miss-type your bindings?
- aliveupstairs 7y agothrow an error saying "incremt is referenced during render..." I personally think this is a non-argument to begin with, but the new API coupled with the fact that Vue supports the render function and JSX would give you what you want.
- ktpsns 7y ago> That said, in React, if you were to mess up a 'token', the runtime would be very upset The same is of course true for Vue. At runtime, it will spit an error if it doesn't know that token (variable, function, whatever it is). My feeling is what you don't like are really the quotation marks because it looks weird. I had a similar feeling when I started with vue. However, it is really a matter of taste if you prefer the Vue @click="foo" or onClick={foo} syntax.
- teniutza 7y agoI agree with you on the preference part. I share the same preference as the GP. I've played a bit with Vue in the past, at the same time I was testing React. I've enjoyed Vue but the strings and template were a grim reminder of the Angular not-so-fun-times and passing members around per-reference and not "per string" made more sense in the general JavaScript way of programming, and so I ended up sticking with React. Even with tooling support, those strings still make me wanting to look away...