Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to resolve directive #603

Closed
rayfranco opened this issue Nov 27, 2014 · 3 comments
Closed

Failed to resolve directive #603

rayfranco opened this issue Nov 27, 2014 · 3 comments

Comments

@rayfranco
Copy link

Custom directive in a sub-component fail to resolve if the directive is on the same node that call the component who owns the directive.

[Vue warn]: Failed to resolve directive: test

Here is a fiddle. This code use to work with previous versions of Vue (even 0.11.rc1)

@yyx990803
Copy link
Member

This is an intended change, but probably should be more explicitly documented. Basically any markup that is in the parent's template will be compiled in the parent's scope - this includes directives written on the component node, and content that's going to be transcluded. So in your example the v-test will be resolved against the foo component instead of bar. In the current 0.11.0 release there's a bug which compiles these directives twice - once in the parent scope and once in the child scope (therefore it throws the warning but the directive still works), but that has been fixed and will be out soon with 0.11.1.

@rayfranco
Copy link
Author

Oh, so I'm falling though the cracks for now :) If I understand well, this will not work at all in the next release?

Since I use Vue, I've always attached my components settings with directives (owned by the component), this change will surely brake my workflow.
Just to give you a basic example, I have a custom video component. I can pass many options to it like callbacks, or even the video path:

<video v-component="video" v-src="page.videoUrl" v-onended="page.next"></video>

What are your thoughts? How could I achieve the same thing without hacking around child references?

@yyx990803
Copy link
Member

The recommended interface for a component is using paramAttributes, and encapsulate directive usage inside the component. So you'd have:

// video component
video: {
  paramAttributes: ['url', 'onended'],
  template: '<video v-src="url" v-onended="onended"></video>',
  replace: true
}

Then when using it:

<video v-component="video" url="page.videoUrl" onended="page.next"></video>

The reasoning behind this is so that the only thing the parent component needs to know about a child component is its paramAttributes (which is basically syntax sugar for v-with), and all it does is passing data down.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants