vue封装组件-笔记

1用vue脚手架安装的项目

2:在src文件夹下的components文件夹下新建ComponentA.vue

<template>
  <div>
    AAAAAAAA
  </div>
</template>

<script>
</script>
export default {
  name: 'ComponentA'
}
<style>
</style>

3:在src文件夹下的components文件夹下新建Component.js

import ComponentA from '@/components/ComponentA' // ComponentA
export default (Vue)=>{
  Vue.component("ComponentA", ComponentA)
}

4:main.js中导入新建的Component.js(注意路径),这两行添加到main.js中

import components from '@/components/components.js'
Vue.use(components);

5;在你需要使用组件的vue页面使用

<ComponentA></ComponentA>

此过程是封装全局组件。

猜你喜欢

转载自www.cnblogs.com/pengxiangchong/p/12762728.html