vue--Register global components

Steps to register global components:

Step 1: Create a new component as usual

What should be noted here is that this component needs to be given a signature. Before, it was just data and methods. Now it is named. In fact, it doesn't matter if you add this name before, but you only use this when registering global components.

<template>
    <div>
        <h3>现在我是一个全局性组件</h3>
    </div>
</template>

<script>
export default {
      
      
    name:"MyFirstComp"
}
</script>

<style>

</style>

Insert image description here

Step 2: Register in main.js

//注册全局性组件
import GolbalComp from './components/GolbalComp.vue'
Vue.component("aNewName", GolbalComp)

Insert image description here

Step 3: Use in App.vue

Different from other ordinary components, you can use it directly here. There is no need to introduce and register it. It has already been registered in main.js.
Insert image description here

Guess you like

Origin blog.csdn.net/weixin_44239550/article/details/128646686