Eric小屋

  • 组件的使用流程:
  • 首页
  • 学习笔记
    • JAVA
    • Spring
    • Node.js
    • Vue
  • 学习文档
  • 案例项目
  • 课程笔记
  • 问题解决
登录

组件的使用步骤

  • Eric
  • 2024-01-02
  • 0

组件的使用流程:

1、创建组件(在components中创建你需要的组件)

2、导入组件(将组件导入到我们需要用到组件的文件)

import MyHead from "./components/MyHead.vue";
import MyFoot from "./components/MyFoot.vue";

3、注册组件(在组件使用前,需要将组件注册到需要的地方)

  • 局部组件(只能在注册的组件内使用)

在我们要注册的组件内 找到components在里面注册组件

export default {
  components: {
    MyHead: MyHead,
    MyFoot,
  },
};
  • 全局组件(所有组件内都能使用)

在main.js文件中import 我们需要注册的全局组件

import HmButton from './components/HmButton'
Vue.component('HmButton', HmButton)

4、使用组件(在组件中的标签语法中直接使用你注册好的组件<MyHead> </MyHead>)

<template>
  <div class="App">
    <MyHead> </MyHead>
    <div class="two">我是中间盒子</div>
    <MyFoot></MyFoot>
  </div>
</template>

以上就是组件化开发中 组建的使用流程

创建组件 → 导入组件 → 注册组件 → 使用组件

联系作者:2572976830@qq.com
© 2025 Eric小屋
Theme by Wing
京ICP备2023032157号 京公网安备11011402053616号
  • {{ item.name }}
  • {{ item.name }}