Importing Vue Components with Webpack

后端 未结 2 458
南笙
南笙 2021-01-01 09:21

I have a hello world Vue app setup with Webpack and have the initial App component working and mounted to body. Although within that App component I can\'t figure out how to

相关标签:
2条回答
  • 2021-01-01 09:54

    You can register it globally like you showed, or if you want to register it locally for use in a single component you need to add it to the components object of the Vue instance:

    <template>
      <top-bar></top-bar>
      <div class="message">{{ message }}</div>
    </template>
    
    <script>
    import TopBar from './top-bar.vue'
    
    export default {
      components: {
        TopBar
      },
      data () {
        return {
          message: 'Hello World'
        }
      }
    }
    </script>
    
    0 讨论(0)
  • 2021-01-01 10:16

    You can give it a suitable name in the components object as shown bellow

    <template>
      <nav-bar></nav-bar>
    </template>
    
    <script>
    import TopBar from './TopBar.vue'
    
    export default {
      components: {
        'nav-bar': TopBar
      }
    }
    </script>
    
    0 讨论(0)
提交回复
热议问题