欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Vue3 組件的開(kāi)發(fā)詳情

 更新時(shí)間:2021年11月15日 09:38:20   作者:久曲健  
這篇文章主要介紹了Vue3組件的開(kāi)發(fā),上一篇文章我們價(jià)紹了Vue3(三)網(wǎng)站首頁(yè)布局開(kāi)發(fā),今天繼續(xù)上篇內(nèi)容展開(kāi)組件的開(kāi)發(fā),需要的朋友可以參考一下

一、前言

果然長(zhǎng)時(shí)間坐著或站著,會(huì)給腰帶來(lái)很大負(fù)擔(dān),聲明下我不是腰脫,就是個(gè)穿刺手術(shù)而已,身上有多處縫針沒(méi)長(zhǎng)好,所以會(huì)給肚子和腰帶來(lái)一定的負(fù)擔(dān)。

上一篇文章已經(jīng)寫(xiě)了關(guān)于布局的開(kāi)發(fā),傳送門(mén)《Vue3(三)網(wǎng)站首頁(yè)布局開(kāi)發(fā) 》,但是我們寫(xiě)代碼,肯定是繼承了優(yōu)秀的代碼風(fēng)格,封裝的特性,所以這里我們?cè)賹?duì)代碼進(jìn)行修改,抽離公共部分的footerheader部分。

二、組件的開(kāi)發(fā)

headerfooter是公共的部分,每個(gè)頁(yè)面都有,所以要抽離出來(lái),然后后續(xù)的維護(hù)再App.vue中維護(hù)即可。

1、組件的構(gòu)成

components下創(chuàng)建組件,基本結(jié)構(gòu)如下:

templatescript兩對(duì)標(biāo)簽構(gòu)成

2、header部分組件的開(kāi)發(fā)

如上圖紅圈部分所示,就是我們要進(jìn)行抽離的公共部分,即組件的開(kāi)發(fā)。

在components下創(chuàng)建組件,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>

3、footer組件的開(kāi)發(fā)

如上圖所示,就是我們要footer部分組件的開(kāi)發(fā),示例代碼如下:

html
<template>
  <a-layout-footer style="text-align: center">
    軟件測(cè)試君 ©2021 Created by 六哥20211017
  </a-layout-footer>
</template>

<script lang="ts">
import { defineComponent } from 'vue';

export default defineComponent({
  name: 'TheFooter',
});
</script>


4、修改App.vue

示例代碼如下:

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>

5、移除Helloword組件及相關(guān)代碼

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>

6、重啟服務(wù)查看

重新編譯,再次訪問(wèn)頁(yè)面結(jié)果如下:

三、最后

到此這篇關(guān)于Vue3(四) 組件的開(kāi)發(fā)的文章就介紹到這了,更多相關(guān)Vue3 組件開(kāi)發(fā)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論