span赋值富文本_教程42——富文本编辑器的原理(项目)

本文介绍了富文本编辑器wangEditor的使用,包括安装和配置过程,并提供了mock数据。通过实例展示了如何在Edit.js和request文件下的index.js中进行集成和操作。
摘要由CSDN通过智能技术生成

3cf7b8a7dbeac5ef110ecea8fa3a0ebb.png

完整版项目的代码链接:

https://github.com/lyandzao/note/tree/master/react/react-tuts/react-admin/src​github.com

mock 数据:

知乎 - 安全中心​rap2.taobao.org

wangEditor - 轻量级web富文本编辑器:

https://gitee.com/huhuachuan/wangEditor​gitee.com

安装:

npm i wangeditor -S

教材的话,例子版本旧了,就不按老版本的案例走了,所以看着官方文档来写。

Edit.js:

import React, { Component } from 'react'

import{
    Card,
    Button,
    Form,
    DatePicker,
    Input
} from 'antd'
import './edit.less'


const formItemLayout = {
  labelCol: {
    span: 4
  },
  wrapperCol: {
    span: 16
  }
}

const config = {
    rules: [{ type: 'object', required: true, message: 'Please select time!' }],
}

class Edit extends Component {
    // 提交表单
    handleSubmit = (e) => {
        // console.log(e)
        e.preventDefault()
        this.props.form.validateFields((err,values) => {
            if(!err){
                console.log('Received values of form: ', values)
            }
        })
    }

    render() {
        console.log(Form);     
        return (
            <Card
              title="编辑文章"
              bordered={false}
              extra={<Button>取消</Button>}
            >
                <Form
                    onSubmit={this.handleSubmit}
                    {...formItemLayout}
                >
                    <Form.Item
                        name="note"
                        label="标题:"
                        rules={[{
                            required: true,
                            message: "标题不能为空"
                        }]}>
                        <Input />
                    </Form.Item>
                    <Form.Item
                        name="note"
                        label="作者:"
                        rules={[{
                            required: true,
                            message: "作者不能为空"
                        }]}>
                        <Input />
                    </Form.Item>
                    <Form.Item
                        name="note"
                        label="阅读量:"
                        rules={[{
                            required: true,
                            message: "阅读量不能为空"
                        }]}>
                        <Input placeholder="0" />
                    </Form.Item>

                    <Form.Item name="date-picker" label="创建时间" {...config}>
                        <DatePicker showTime placeholder="选择时间" />
                    </Form.Item>

                    <Form.Item name={['user', 'introduction']} label="Introduction">
                        <Input.TextArea />
                    </Form.Item>

                    <div ref={this.editoeRef}>这里是内容...</div>

                    <Button type="primary" htmlType="submit">
                        保存修改
                    </Button>
                </Form>
            </Card>
        )
    }
}

export default Edit

request 文件下的 index.js:

import axios from 'axios'
import { message } from 'antd'
const isDev = process.env.NODE_ENV === 'development'

const service = axios.create({
  baseURL: isDev ? 'http://rap2api.taobao.org/app/mock/176929' : ''
})

//请求拦截器

service.interceptors.request.use((config) => {
  config.data = Object.assign({}, config.data, {
    // authToken: window.localStorage.getItem('authToken')
    authToken: 'itisatokenplaceholder'
  })
  return config
})

service.interceptors.response.use((resp) => {
  if (resp.data.code === 200) {
    return resp.data.data
  } else {
    // 全局处理错误
    message.error(resp.data.errMsg)
  }
})


// 获取文章列表
export const getArticles = (offset = 0, limited = 10) => {
  return service.post('/api/v1/articleList', {
    offset,
    limited
  })
}

//通过id删除文章
export const deleteArticleById = (id) => {
  return service.post(`/api/v1/articleDelete`,{id})
}

//通过id获取文章
export const getArticleById = (id) => {
  return service.post(`/api/v1/article/${id}`)
}

55e218fc693f3b50d35952c7577861e6.png
结果
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值