博文业务代码实现和Antd组件--Django播客系统(十一)

导航菜单

import React from 'react';
import ReactDom from 'react-dom';
import {
   Route,Link,BrowserRouter as Router} from "react-router-dom";
import Login from "./component/login";
import Reg from "./component/reg";
import {
   Menu} from 'antd'; //加载antd的组件

import 'antd/lib/menu/style'; //加载组件的样式css
import {
    HomeFilled,LoginOutlined,RotateRightOutlined,AccountBookFilled } from '@ant-design/icons';


const App = () =>  (
    <Router>
        <div>
            <div>
                <Menu mode="horizontal" theme="dark"  style={
   {
    lineHeight: '64px' }} defaultSelectedKeys= {
   ['home']} >
                    <Menu.Item key="home" icon={
   <HomeFilled />} ><Link to="/">主页</Link></Menu.Item>
                    <Menu.Item key="login" icon={
   <LoginOutlined />}><Link to="/login">登录</Link></Menu.Item>
                    <Menu.Item key="reg" icon={
   <RotateRightOutlined />}><Link to="/reg">注册</Link></Menu.Item>
                    <Menu.Item key="about" icon={
   <AccountBookFilled />}><Link to="/about">关于</Link></Menu.Item>
                </Menu>
            </div>
            <div>
                <Route path="/about" component={
   About} />
                <Route path="/login" component={
   Login} />
                <Route path="/reg" component={
   Reg} />
                <Route exact path="/" component={
   Home} />
            </div>
        </div>
    </Router>
);

function Home() {
   
    return (
        <div>
        <h2>Home</h2>
        </div>
    );
}

function About() {
   
    return (
        <div>
        <h2>About</h2>
        </div>
    );
}


ReactDom.render(<App />, document.getElementById('root'));

001

页面布局

  1. 修改src/index.js导航菜单
import React from 'react';
import ReactDom from 'react-dom';
import {
   Route,Link,BrowserRouter as Router} from "react-router-dom";
import {
   Menu,Layout} from 'antd'; //加载antd的组件

import Login from "./component/login";
import Reg from "./component/reg";

import 'antd/lib/menu/style'; //加载组件的样式css
import 'antd/lib/layout/style';
import {
    HomeFilled,LoginOutlined,RotateRightOutlined,AccountBookFilled } from '@ant-design/icons';

const {
   Header,Content,Footer} = Layout; // 上中下

const App = () =>  (
	<Router>
		<Layout>
			<Header>
				<Menu mode="horizontal" theme="dark"  style={
   {
    lineHeight: '64px' }} defaultSelectedKeys= {
   ['home']} >
					<Menu.Item key="home" icon={
   <HomeFilled />} ><Link to="/">主页</Link></Menu.Item>
					<Menu.Item key="login" icon={
   <LoginOutlined />}><Link to="/login">登录</Link></Menu.Item>
					<Menu.Item key="reg" icon={
   <RotateRightOutlined />}><Link to="/reg">注册</Link></Menu.Item>
					<Menu.Item key="about" icon={
   <AccountBookFilled />}><Link to="/about">关于</Link></Menu.Item>
				</Menu>
			</Header>
			<Content style={
   {
    padding: '8px 50px' }}>
				<div style={
   {
    background: '#fff', padding: 24, minHeight: 280 }}>
					<Route path="/about" component={
   About} />
					<Route path="/login" component={
   Login} />
					<Route path="/reg" component={
   Reg} />
					<Route exact path="/" component={
   Home} />
				</div>
			</Content>
			<Footer style={
   {
    textAlign: 'center' }}>xddweb©2019-2020 </Footer>
		</Layout>
  </Router>
);

function Home() {
   
  return (
    <div>
      <h2>Home</h2>
    </div>
  );
}

function About() {
   
  return (
    <div>
      <h2>About</h2>
    </div>
  );
}


ReactDom.render(<App />, document.getElementById('root'));

002

博文业务

url method 说明
/posts/ POST 提交博文的title、content,成功返回json,包含post_id,title
/posts/id GET 返回博文详情
返回json,id,title、author_id、postdate(时间戳)、content
/posts/ GET 返回博文标题列表,分页

业务层

  • 创建service/post.js文件,新建PostService类。
import axios from 'axios';
import {
   observable} from 'mobx';

class PostService{
   
    @observable msg = '';

    pub(title,content){
   
        console.log(title);
        axios.post('/api/posts/',{
   
            title,content
        })/* dev server 会代理 */
        .then(
            response => {
   
                console.log(response.data);
                console.log(response.status);
                this.msg = '博文提交成功';
            }
        ).catch(
            error => {
   
                console.log(error);
                this.msg = '博
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值