Global and local registration component global method mounting

1. Global and local registration components

1. Globally register components

When it is used in many modules, it should be registered as a global component. The benefit of the global component is that it only needs to be registered once and can be used anywhere in the project. To register as a global component, it must be introduced in main.js

import Demo from '../components/lib/demo/src/main.vue'

Vue.component('Demo',Demo)

Use <Demo /> on the required page

2. Locally registered components

<template>

     <index-page /> 

<template/>

<script>

import indexPage from '../../../components/Pagination/index.vue'

    export default {

        components: { indexPage }

    }

<script/>

Second, the global method mount

1. Global method mount

Define public methods in the new public.js file in the utils folder

export  function parseTime(){    }

export  function resetForm (){    }

Mount in the main.js file

import { parseTime, resetForm } from '.@/utils/public'

Vue.prototype.parseTime = parseTime

Vue.prototype.resetForm = resetForm

Use on required pages

<div> { { parseTime() }}</div>

<div> { { resetForm() }}</div>

Guess you like

Origin blog.csdn.net/m0_63304840/article/details/127408972