从零开发基于chatGPT的社区交友系统 (前后端分离)丨主页框架 03

本文介绍了如何在Vue.js项目中搭建主页框架,包括引用iconfont字体图标,设计页面结构,以及实现路由局部跳转。作者通过创建header、nav和content组件,展示了如何布局和切换主题,并提供了相关代码示例。同时,文章也提及了路由配置和组件的使用。
摘要由CSDN通过智能技术生成

前言

  • 上一章我们实现了基础的主题切换功能,这一章我们开始搭建主页主要框架,并测试一下我们的切换主题功能。

开工

引用iconfont字体图标

  • 这里我们使用font-class方法引用iconfont字体图标。
  • 在项目目录的src\assets\icons中创建iconfont.css文件。
  • 首先我们将选中的图标放入项目,点击标红部分,如下图:
    在这里插入图片描述
  • 在弹出的页面中将代码复制进刚刚创建的iconfont.css文件中,代码如下:
@font-face {
  font-family: "iconfont"; /* Project id 3990496 */
  src: url('//at.alicdn.com/t/c/font_3990496_c7efy0697zw.woff2?t=1684920260831') format('woff2'),
       url('//at.alicdn.com/t/c/font_3990496_c7efy0697zw.woff?t=1684920260831') format('woff'),
       url('//at.alicdn.com/t/c/font_3990496_c7efy0697zw.ttf?t=1684920260831') format('truetype');
}

.iconfont {
  font-family: "iconfont" !important;
  font-size: 16px;
  font-style: normal;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.icon-wode:before {
  content: "\e74d";
}

.icon-zhuye:before {
  content: "\e63b";
}

.icon-xiaoxi1:before {
  content: "\e741";
}

.icon-sousou:before {
  content: "\e63a";
}

.icon-qq:before {
  content: "\e600";
}

.icon-weixin:before {
  content: "\e665";
}

.icon-guanbi:before {
  content: "\e6c1";
}

  • main.js文件中引用,这样就可以全局使用啦。
import '@/assets/icons/iconfont.css'
  • 使用方法如下:
<i class="iconfont icon-sousou"></i>

template代码

  • 这里我的思路是主框架分为上下两部分。
  • 上为头部,使用绝对定位置于最上层。
  • 下为主要内容,分为左右两部分,左边为导航栏,右边为路由页面展示部分。
  • 主框架思路:
  <div class="container">
    <div class="header"></div>
    <div class="main">
      <div class="nav"></div>
      <div class="content"></div>
    </div>
  </div>
  • 头部为左中右布局,左边logo,中间搜索框,右边留几个按钮,如下:
	<div class="header">
      <img class="logo" src="@/assets/icons/logo.png">
      <div class="search-box">
        <input placeholder="搜索">
        <div class="search-icon">
          <i class="iconfont icon-guanbi"></i>
          <i class="iconfont icon-sousou"></i>
        </div>
      </div>
      <div class="right">
        <button @click="switchTheme('default')">极简白</button>
        <button @click="switchTheme('dark')">暗夜黑</button>
        <button>打赏</button>
        <button>关于我们</button>
      </div>
    </div>
  • 导航栏部分如下:
      <div class="nav">
        <div class="nav-item" :class="communityState" @click="routerPush('community')">
          <i class="iconfont icon-zhuye"></i>
          <div>社区</div>
        </div>
        <div class="nav-item" :class="chatState" @click="routerPush('chat')">
          <i class="iconfont icon-xiaoxi1"></i>
          <div>聊天</div>
        </div>
        <div class="nav-item" :class="userState" @click="routerPush('user')">
          <i class="iconfont icon-wode"></i>
          <div>我的</div>
        </div>
      </div>
  • 主内容即路由内容部分使用<router-view>左右路由页面占位。
  • 主内容部分如下:
      <div class="content">
        <router-view></router-view>
      </div>

style代码

.container {
  height: 100%;
  width: 86%;
  margin: 0 auto;
}

.header {
  padding-top: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: fixed;
  width: 86%;
  margin: 0 auto;
  background-color: @backgroundColor;

  .logo {
    height: 3rem;
  }

  .search-box {
    background-color: @boxBackgroundColor;
    width: 30rem;
    border-radius: 2rem;
    position: fixed;
    left: 50%;
    transform: translate(-50%);
    padding: 0 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;

    input {
      background-color: @boxBackgroundColor;
      flex: 1;
      border: none;
      outline: none;
      font-size: @textSize2;
      color: @primaryText;
      width: auto;
      line-height: 2.4rem;
    }
    .search-icon{
      display: flex;
      i {
        color: @secondary;
        padding: 0 0.6rem;
      cursor: pointer;
      }
    }
  }

  .right {
    display: flex;

    button {
      padding: 0.5rem 1.2rem;
      border: none;
      border-radius: 2rem;
      background-color: transparent;
      font-size: @textSize2;
      color: @primaryText;
      cursor: pointer;
    }
    button:hover{
      background-color: @boxBackgroundColor;
    }
  }
}

.main {
  padding-top: 5.6rem;
  display: flex;
  height: 100%;
  box-sizing: border-box;
}

.nav {
  flex: 1;

  .nav-item {
    display: flex;
    align-items: center;
    font-size: @textSize2;
    color: @primaryText;
    font-weight: 600;
    padding: 0.8rem 1rem;
    margin-bottom: 0.5rem;
    border-radius: 2rem;
    cursor: pointer;
    i{
      font-size: 1.5rem;
    }
    div {
      margin-left: 0.8rem;
    }
  }
  .selected{
    background-color: @boxBackgroundColor;
  }
  .nav-item:hover{
      background-color: @boxBackgroundColor;
    }
}

.content {
  flex: 5;
  padding-left: 2rem;
  overflow-y: scroll;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.content::-webkit-scrollbar{
  display: none;
}
.content::-moz-scrollbar{
  display: none;
}

页面展示

在这里插入图片描述

路由局部跳转

  • 在项目目录的src\components目录中新建如下三个vue文件:
//community.vue
<template>
    <div>
        社区
    </div>
</template>

//chat.vue
<template>
    <div>
        聊天
    </div>
</template>

//user.vue
<template>
    <div>
        我的
    </div>
</template>
  • 路由配置,在router/index.js添加如下配置:
  • 其中,主路由页面是index.vue,该路由有三个子路由。
{
    path: '/',
    name: 'Index',
    component: () => import('../views/index'),
    children: [{
      path: '/user',
      name: 'User',
      component: () => import('../components/user')
    },
    {
      path: '/community',
      name: 'Community',
      component: () => import('../components/community')
    },
    {
      path: '/chat',
      name: 'Chat',
      component: () => import('../components/chat')
    }]
  },

script代码

  • js代码这里主要实现了头部的两个皮肤切换,以及导航栏的路由局部刷新功能,如下:
<script setup>
import { setTheme } from '@/theme/theme'
import { useRouter } from 'vue-router'
import { ref, onMounted } from 'vue'
const router = useRouter()
const userState = ref('noSelected')
const communityState = ref('noSelected')
const chatState = ref('noSelected')
onMounted(() => {
  routerPush('community')
})
const switchTheme = (theme) => {
  setTheme(theme)
}
const routerPush = (path) => {
  router.push(path)
  communityState.value = 'noSelected'
  chatState.value = 'noSelected'
  userState.value = 'noSelected'
  switch (path) {
    case 'community':
      communityState.value = 'selected'
      break
    case 'chat':
      chatState.value = 'selected'
      break
    case 'user':
      userState.value = 'selected'
      break
    default:
      communityState.value = 'selected'
  }
}
</script>

总结

  • 至此,主页框架就基本完成了,上述的一些功能也可以正常使用,录制gif有点麻烦这里就没有展示,后面会不断完善细节。小伙伴们可以将自己的意见反馈发表到评论区,有合作想法的铁子欢迎私聊。。。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
若依框架支持前后端分离的二次开发。根据引用中的描述,可以将自己系统的业务处理放在新建模块中,同时保持若依源码不变。具体做法是将controller层放在wms-admin模块进行管理,将domain、mapper、service和xml文件放在新建模块中进行管理。这样可以方便地进行业务扩展和定制化开发。 在主模块的pom文件中,可以引用新建模块的依赖,以实现主模块对新建模块的功能扩展。引用中的代码示例展示了如何在pom文件中引用新建模块。通过添加dependency标签,并指定新建模块的groupId、artifactId和version,就可以将新建模块的功能引入到主模块中。 在进行若依框架的二次开发之前,需要满足一些前置条件。引用中列举了一些主要的要求,包括JDK版本、Mysql版本、Redis版本、Maven版本、Node版本和nacos版本。确保满足这些要求可以保证二次开发的顺利进行。 总结起来,若依框架支持前后端分离的二次开发。可以通过在新建模块中管理自己系统的业务处理,同时保持若依源码不变。可以通过在主模块的pom文件中引用新建模块的依赖来扩展功能。在开始二次开发之前,需要满足一些前置条件,如特定的JDK、数据库、Redis、Maven、Node和nacos版本要求。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [若依框架前后端分离使用2](https://blog.csdn.net/Hello_World_Me/article/details/125198350)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *3* [若依框架前后端分离使用1](https://blog.csdn.net/Hello_World_Me/article/details/125142393)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

_Kaiser

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值