David Marko
David Marko

Reputation: 2519

Custom directive and directive parameters

I'm adapting the select2 example here http://vuejs.org/examples/select2.html for my project and I need to send some arguments to directive like multiple:true/false etc. This params are going to be used for select2 initialization in directive bind method. How can I accomplish this? In directive docs here http://vuejs.org/guide/custom-directive.html there are some hints e.g.

<div id="demo" v-demo="LightSlateGray : msg"></div> 

... but its only one argument, can I have more?

Upvotes: 2

Views: 6240

Answers (1)

David K. Hess
David K. Hess

Reputation: 17246

You have two basic options:

  1. Put all of your arguments in an object and pass that single object to the directive.
  2. You can use multiple clauses in the directive itself. See here for more information: https://012.vuejs.org/guide/custom-directive.html#Multiple_Clauses

EDIT: multiple clauses above applied to Vue version 0.12. With version 2, that's no longer an option - use an object.

Upvotes: 3

Related Questions