首页 前端知识 Vue 全组件 局部组件

Vue 全组件 局部组件

2025-02-24 13:02:45 前端知识 前端哥 615 605 我要收藏

一、组件定义和使用

1、全局组件

定义

<template>

    <div>

        <h1>This is a global component</h1>

    </div>

</template>

<script lang="ts">

</script>

<style></style>

 

导入

全局组件在main.ts(Vue TS的项目)引入,

或者在main.js(Vue JS的项目)引入

import { createApp } from 'vue'

import App from './App.vue'

import router from './router'

import store from './store'

import GlobalComponent  from "../src/components/component/GlobalComponent.vue";

const app = createApp(App)

app.component("GlobalComponent",GlobalComponent);

app.use(store).use(router).mount('#app')

 

使用 

全局组件可以在任意组件中使用,不需要再次导入

转载请注明出处或者链接地址:https://www.qianduange.cn//article/21094.html
标签
评论
发布的文章

C/C | 每日一练 (2)

2025-02-24 13:02:49

Linux性能监控工具汇总

2025-02-24 13:02:48

Python常见面试题的详解16

2025-02-24 13:02:48

QQ登录测试用例报告

2025-02-24 13:02:47

大家推荐的文章
会员中心 联系我 留言建议 回顶部
复制成功!