1

How does Vue.js know <my-component> equals/is MyComponent?

<template>
    <!-- Vue.js correctly inserts the component here
         But how does it know my-component = MyComponent? -->
    <my-component></my-component>
</template>

<script type="text/javascript">
import MyComponent from '../MyComponent.vue'

export default {

    components: {
        MyComponent
    }
}

</script>
2
  • 1
    I hope you read this Commented Apr 17, 2018 at 8:42
  • @C2486 thanks that answers my question. If you create an answer I can accept it. Commented Apr 17, 2018 at 8:49

1 Answer 1

1

It is a fairly standard convention that APIs like Vue has will convert between kebab-case and PascalCase / camelCase because HTML is case insensitive.

See this info here: https://v2.vuejs.org/v2/style-guide/#Component-name-casing-in-JS-JSX-strongly-recommended

More specifically it "knows" because vue contains methods to parse camelCase, kebab-case (snake-case) in strings, props, etc.

You can see how this might be done in the util.js file found in vue/src/shared/util.js around line 157. see camelize and hyphenate

I believe PascalCase is simply handled using camelize combined with thecapitalize utility. Something like...

var camelized = camelize();
var pascalized = capitalize(camelized);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.