Giter VIP home page Giter VIP logo

blog's Introduction

项目简介

使用react搭建的个人博客。

功能

  • 首页列表,加载所有的文章,预览文章的部分内容,同时显示赞、评论、浏览的数量。
  • 文章发布。
  • 文章页,能查看详细文章内容,点赞数以及评论。
  • 文章的点赞功能。
  • 用户的登录与注册。
  • 用户能进行评论并管理自己的评论

运用的技术主要有:

  • 采用react技术栈,所有状态均由redux进行管理,通过react-router来设置页面路由。
  • 使用express+mongolass进行后台数据的管理与操作。
  • 前后端分离,使用jquery的ajax携带cookie进行数据交互。
  • 使用react-s-alert插件弹出提示消息。
  • 使用babel转译、webpack打包代码。
  • 使用Ant Motion动画框架实现页面切换动画。
  • nodejs开启gzip压缩。

预览

博客

运行项目

  git clone https://github.com/tangkai123456/blog.git
  cd blog
  npm install
  node server

状态树

本项目使用redux管理状态,状态树为:

state={
    loginState,//存储登录状态,管理员登录时为2,普通用户登陆时为1,未登录为0
    getData:[//首页时存储所有文章信息,单文章页存储一篇文章的信息,但两种情况数据类型都为数组,但文章页时数组长度为1
            {
                ...postContent,//文章信息
                comments:[]//文章的评论,首页时没有这个属性
            },
        ]
    }

redux

异步ajax使用了thunk中间件,thunk允许action的创建函数返回一个函数,满足条件的情况下才dispatch。

使用三个action进行标记,获取文章相关数据的actionCreator形式为: 1.发起请求时dispatch("GET_DATA") 2.请求成功并且获取数据时dispatch("GET_DATA_SUCCESS") 3.请求失败时dispatch("GET_DATA_ERROR")

项目中所有ajax数据请求都在action中,也只有ajax可以调用dispatch改变状态树,在组件中不直接调用dispatch,数据流清晰

mongoDB数据结构

用户:

User={
    name:{type:"string"},
	password:{type:"string"},
}

文章:

Post={
    title:{type:"string"},
	content:{type:"string"},
	good:[{type:"string"}],//点赞数
	updateTime:{type:"string"},
	pv:{type:"number"}//浏览数
}

评论:

Comment={
    postId:{type:Mongolass.Types.ObjectId},
	name:{type:"string"},
	content:{type:"string"},
}

待完善的功能

  • react-router过渡动画(已完成部分动画)
  • 加速首屏加载速度(已增加后台gzip压缩)
  • 聊一聊
  • 关于

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.