-
-
Notifications
You must be signed in to change notification settings - Fork 33.6k
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
Vue using wrong component when there're global and local components with same name but registered with different naming conventions #4434
Comments
change it to: new Vue({
el: '#app',
components: {
'x-foo': {
template: '<div>local foo component won\'t show</div>'
}
}
})
|
^ As above |
I exactly know changing to |
@yyx990803 @fnlctrl What do you think? |
And how can I know what naming conventions the third party UI libraries are using? Will my local components with the same name conflict with theirs? Who knows. |
Why would it be relevant? You can always alias them inside the Consider the reverse scenario, where you want to override a third party component's local component Anyway, you should always explicitly alias components if there is a potential naming conflict, and never rely on the fallback precedence. |
The real scenario is, when we use a UI collection set. we simply import SomeUI from 'some-ui'
Vue.use(SomeUI) We don't need to care about whether it's registered with kebab-case, camelCase, or TitleCase. If we register a local component , we simply do: <template>
<div>
<tab-pane>something</tab-pane>
</div>
</template>
<script>
import TabPane from './TabPane.vue'
export default {
components: {
TabPane
}
}
</script> But what if SomeUI also has a component named 'tab-pane', and it is registered with: Vue.component('tab-pane', {...}) Then the local registered component will never be used. We have to use a longer syntax: export default {
component: {
'tab-pane': TabPane
}
} And what you said overriding a thirty UI's local component with a global component is a rare case, it's like a hack. And if it's local component is registered with kebab-case, you'd never had a chance. And, the vue guide says:
And you just told me vue cares about it, and we should care about it too! |
That's not what I said. Let me quote my words again:
In your case you're creating a component that has the same name of a 3rd party component, which should have been avoided in the first place, since it's you defining the local component and you have full control over its name. |
Please don't play with words. What the fact is I registered a component with the wrong naming convention and Vue cares about it. Please let @yyx990803 to end the dispute. |
Yeah, you can say, it's not a bug, it's a feature, doc is wrong, not the code. |
I think this is a bug, camel case and title case component name seems aliases rather than fallback. Practically, we use camel/title case to register local component (with ES6 object shorthand) since JavaScript does not allow kebab case as variable names. And also, local component should not be overridden by global components. It can easily cause unexpected behavior and break capsulations of third party components. |
Sounds reasonable, but maybe it will bring a breaking change. |
What about using both of them ( |
@JounQin Here is what happend internally. Line 322 in 8c0fac6
const res = assets[id] ||
// camelCase ID
assets[camelize(id)] ||
// Pascal Case ID
assets[capitalize(camelize(id))] with So I think it might bring breaking change in some cases if we apply the new resolving strategy. |
JSFiddle: http://jsfiddle.net/fenivana/3y7hzwg8/
The text was updated successfully, but these errors were encountered: