Vue3组件开发学习中有哪些知识点要掌握了解
Admin 2022-06-20 群英技术资讯 1356 次浏览
这篇文章主要介绍了Vue3组件开发学习中有哪些知识点要掌握了解相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇Vue3组件开发学习中有哪些知识点要掌握了解文章都会有所收获,下面我们一起来看看吧。果然长时间坐着或站着,会给腰带来很大负担,声明下我不是腰脱,就是个穿刺手术而已,身上有多处缝针没长好,所以会给肚子和腰带来一定的负担。
上一篇文章已经写了关于布局的开发,传送门《Vue3(三)网站首页布局开发 》,但是我们写代码,肯定是继承了优秀的代码风格,封装的特性,所以这里我们再对代码进行修改,抽离公共部分的footer和header部分。
header和footer是公共的部分,每个页面都有,所以要抽离出来,然后后续的维护再App.vue中维护即可。
在components下创建组件,基本结构如下:

由template和script两对标签构成

如上图红圈部分所示,就是我们要进行抽离的公共部分,即组件的开发。
在components下创建组件,header部分组件代码如下:
html
<template>
<a-layout-header class="header">
<div class="logo" />
<a-menu
theme="dark"
mode="horizontal"
v-model:selectedKeys="selectedKeys1"
:style="{ lineHeight: '64px' }"
>
<a-menu-item key="1">nav 11122</a-menu-item>
<a-menu-item key="2">nav 2</a-menu-item>
<a-menu-item key="3">nav 3</a-menu-item>
</a-menu>
</a-layout-header>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
export default defineComponent({
name: 'TheHeader',
});
</script>

如上图所示,就是我们要footer部分组件的开发,示例代码如下:
html
<template>
<a-layout-footer style="text-align: center">
软件测试君 ©2021 Created by 六哥20211017
</a-layout-footer>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
export default defineComponent({
name: 'TheFooter',
});
</script>
示例代码如下:
html
<template>
<a-layout>
<the-header></the-header>
<router-view/>
<the-footer></the-footer>
</a-layout>
</template>
<style>
#components-layout-demo-top-side-2 .logo {
float: left;
width: 120px;
height: 31px;
margin: 16px 24px 16px 0;
background: rgba(255, 255, 255, 0.3);
}
.ant-row-rtl #components-layout-demo-top-side-2 .logo {
float: right;
margin: 16px 0 16px 24px;
}
.site-layout-background {
background: #fff;
}
</style>
<script>
import TheHeader from "@/components/the-header";
import TheFooter from "@/components/the-footer";
export default {
components: {
TheHeader,
TheFooter
}
}
</script>
home修改如下:
html
<template>
<a-layout>
<a-layout-sider width="200" style="background: #fff">
<a-menu
mode="inline"
v-model:selectedKeys="selectedKeys2"
v-model:openKeys="openKeys"
:style="{ height: '100%', borderRight: 0 }"
>
<a-sub-menu key="sub1">
<template #title>
<span>
<user-outlined />
subnav 1
</span>
</template>
<a-menu-item key="1">option1</a-menu-item>
<a-menu-item key="2">option2</a-menu-item>
<a-menu-item key="3">option3</a-menu-item>
<a-menu-item key="4">option4</a-menu-item>
</a-sub-menu>
<a-sub-menu key="sub2">
<template #title>
<span>
<laptop-outlined />
subnav 2
</span>
</template>
<a-menu-item key="5">option5</a-menu-item>
<a-menu-item key="6">option6</a-menu-item>
<a-menu-item key="7">option7</a-menu-item>
<a-menu-item key="8">option8</a-menu-item>
</a-sub-menu>
<a-sub-menu key="sub3">
<template #title>
<span>
<notification-outlined />
subnav 3
</span>
</template>
<a-menu-item key="9">option9</a-menu-item>
<a-menu-item key="10">option10</a-menu-item>
<a-menu-item key="11">option11</a-menu-item>
<a-menu-item key="12">option12</a-menu-item>
</a-sub-menu>
</a-menu>
</a-layout-sider>
<a-layout-content
:style="{ background: '#fff', padding: '24px', margin: 0, minHeight: '280px' }"
>
Content
</a-layout-content>
</a-layout>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
export default defineComponent({
name: 'Home',
});
</script>
重新编译,再次访问页面结果如下:

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
在React的生命周期钩子和合成事件中,多次执行setState,会被调用几次,本文就详细的介绍一下,感兴趣的可以了解一下
这篇文章主要为大家详细介绍了Vue实现简易记事本功能,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
这篇文章主要为大家介绍了JavaScript中的原型和原型链,具有一定的参考价值,感兴趣的小伙伴们可以参考一下,希望能够给你带来帮助<BR>
本篇文章给大家带来了关于javascript的相关知识,其中主要整理了异步与回调的基本概念的相关问题,同步,一般指按照预定的顺序依次执行任务,只有当上一个任务完成后,才开始执行下一个任务,异步,与同步相对应,异步指的是让CPU暂时搁置当前任务,先处理下一个任务,当收到上个任务的回调通知后,再返回上个任务继续执行,下面一起来看一下,希望对大家有帮助。
JavaScript中怎么实现继承?下面本篇文章给大家分享JS实现继承的6种方法,希望对大家有所帮助!
成为群英会员,开启智能安全云计算之旅
立即注册关注或联系群英网络
7x24小时售前:400-678-4567
7x24小时售后:0668-2555666
24小时QQ客服
群英微信公众号
CNNIC域名投诉举报处理平台
服务电话:010-58813000
服务邮箱:service@cnnic.cn
投诉与建议:0668-2555555
Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 ICP核准(ICP备案)粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008