SpringBoot知识体系+Vue3 实战WIKI知识库系统笔记 demo6_vue

Posted dlage

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SpringBoot知识体系+Vue3 实战WIKI知识库系统笔记 demo6_vue相关的知识,希望对你有一定的参考价值。

集成ant design

npm install ant-design-vue@next --save

引入 main.js

import  createApp  from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import Antd from 'ant-design-vue'; // 引入 ant design
import 'ant-design-vue/dist/antd.css';


createApp(App).use(store).use(router).use(Antd).mount('#app')

使用:https://next.antdv.com/components/button-cn 直接在html中使用即可。

<template>
  <div class="home">
    <img alt="Vue logo" src="../assets/logo.png">
    <HelloWorld msg="Welcome to Your Vue.js App"/>
    <a-button type="primary">Primary Button</a-button>
  </div>
</template>

<script>
// @ is an alias to /src
import HelloWorld from '@/components/HelloWorld.vue'

export default 
  name: 'Home',
  components: 
    HelloWorld
  

</script>

页面布局

打开下面的网站,里面有各种各样的组件可以直接使用。这里我选择了layout的一个布局。

https://next.antdv.com/components/layout-cn

vue-cliApp.vue 页面改成下面的布局。删除App.vue原有的scriptcss将layout的templatecss复制进来即可。

<template>
  <a-layout>
    <a-layout-header class="header">
      <div class="logo" />
      <a-menu
          v-model:selectedKeys="selectedKeys1"
          theme="dark"
          mode="horizontal"
          :style=" lineHeight: '64px' "
      >
        <a-menu-item key="1">nav 1</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>
    <a-layout>
      <a-layout-sider width="200" style="background: #fff">
        <a-menu
            v-model:selectedKeys="selectedKeys2"
            v-model:openKeys="openKeys"
            mode="inline"
            :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>
    <a-layout-footer style="text-align: center">
      Ant Design ©2018 Created by Ant UED
    </a-layout-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>

router-view动态获取内容

将中间的内容提取到Home.vue里面。实现router-view动态获取内容

第一步:直接将中间的a-layout搬到Home.vuetemplate里面

<template>
  <a-layout>
    <a-layout-sider width="200" style="background: #fff">
      <a-menu
          v-model:selectedKeys="selectedKeys2"
          v-model:openKeys="openKeys"
          mode="inline"
          :style=" height: '100%', borderRight: 0 "
      >
        <a-sub-menu key="sub1">
          <template #title>
              <span>
                <user-outlined />
                subnav 1
              </span>
          </template>
          <a-menu-item key="1">option11111</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>
// @ is an alias to /src
import HelloWorld from '@/components/HelloWorld.vue'

export default 
  name: 'Home',
  components: 
    HelloWorld
  

</script>

第二步:使用<router-view/>替代原有的a-layout

<template>
  <a-layout>
    <a-layout-header class="header">
<!--      <div class="logo" />-->
      <a-menu
          v-model:selectedKeys="selectedKeys1"
          theme="dark"
          mode="horizontal"
          :style=" lineHeight: '64px' "
      >
        <a-menu-item key="1">nav 1</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>
      <router-view/>
    <a-layout-footer style="text-align: center">
      Roc ©2021 Created by Roc
    </a-layout-footer>
  </a-layout>
</template>

使用component

headerfooter提取成为component

<template>
  <a-layout-header class="header">
    <!--      <div class="logo" />-->
    <a-menu
        v-model:selectedKeys="selectedKeys1"
        theme="dark"
        mode="horizontal"
        :style=" lineHeight: '64px' "
    >
      <a-menu-item key="1">nav 1111</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>
export default 
  name: 'the-header',

</script>

app.vue中导入并使用

<template>
  <a-layout>
    <theHeader/>
      <router-view/>
    <theFooter/>
  </a-layout>
</template>

<script>
// @ is an alias to /src
import theHeader from '@/components/the-header'
import theFooter from '@/components/the-footer'

export default 
  name: 'App',
  components: 
    theHeader, theFooter
  

</script>

使用组件并加入数据

<template>
  <a-layout>
    <a-layout-content
        :style=" background: '#fff', padding: '24px', margin: 0, minHeight: '280px' "
    >
      <a-list item-layout="vertical" size="large" :grid=" gutter: 20, column: 3 " :data-source="ebooks">
        <template #footer>
          <div>
            <b>Roc design vue</b>
            footer part
          </div>
        </template>
        <template #renderItem=" item ">
          <a-list-item key="item.name">
            <template #actions> <!--这里是三个小图标-->
              <span v-for=" type, text  in actions" :key="type">
                <component :is="type" style="margin-right: 8px" />
                 text 
              </span>
            </template>

            <a-list-item-meta :description="item.description"&g

以上是关于SpringBoot知识体系+Vue3 实战WIKI知识库系统笔记 demo6_vue的主要内容,如果未能解决你的问题,请参考以下文章

SpringBoot知识体系+Vue3 实战WIKI知识库系统笔记 demo4_mybatis_Example

SpringBoot知识体系+Vue3 实战WIKI知识库系统笔记 demo4_mybatis_Example

SpringBoot知识体系+Vue3 实战WIKI知识库系统笔记 demo1_mybatis_generator

SpringBoot知识体系+Vue3 实战WIKI知识库系统笔记 demo1_mybatis_generator

SpringBoot知识体系+Vue3 实战WIKI知识库系统笔记 demo6_vue

SpringBoot知识体系+Vue3 实战WIKI知识库系统笔记 demo6_vue