vuejs / v2.vuejs.org

📄 Documentation for Vue 2
https://v2.vuejs.org
MIT License
5.04k stars 3.43k forks source link

Example of dynamic argument in custom-directive.md is incorrect #2155

Open oohira opened 5 years ago

oohira commented 5 years ago

In #2062, an example of dynamic argument for custom directive was added. However, the intension is not clear because

  1. if it means dynamic arguments introduced in v2.6, the example should be mydirective:[argument]=dataproperty instead of mydirective:argument=[dataproperty]
  2. if it means just passing the argument dynamically, the example should be mydirective:argument=dataproperty instead of mydirective:argument=[dataproperty]. But this is already described in the previous example v-demo:foo.a.b="message"

I think the following example may be close to the original intention.

cc: @bk-dev @sdras

phanan commented 5 years ago

Pinging @sdras

bk-dev commented 5 years ago

If I'm totally honest, I was confused as well. Mainly because in my code base the syntax was different than what was outlined by @sdras. An example usage in my code base is <div v-my-directive:[dynamicArg]></div>. That said, I have never had a need to use =dataproperty to create a statement.

My original goal was to pass a data property to a directive and when that data property changed the directive update hook would get invoked so the directive could react to the change. Doing something like 2) from @oohira's post would not have worked (at least not in my testing).

Here was my original commit: https://github.com/vuejs/vuejs.org/pull/2062/commits/ea850654100ae617005531a692fb287d5d62bbf8

sdras commented 5 years ago

Yep, this was my fault for not reading through more thoroughly. I rewrote this section with clearer examples (thank you for the fiddle @oohira), but also rewrote the explanation to be more conversational in our docs style, and explain the problem space/use case. Let me know if that clears things up for you. Thanks for the issue!