Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component, createRef } from "react";
  2. import { Card, Button, Form, Input, DatePicker } from "antd";
  3. import { FileOutlined, GithubOutlined, EyeOutlined } from "@ant-design/icons";
  4. import E from "wangeditor";
  5. import "./edit.less";
  6. // console.log(E);
  7.  
  8. export default class ArticleEdit extends Component {
  9.   constructor() {
  10.     super();
  11.     this.editorRef = createRef();
  12.   }
  13.  
  14.   //? wangeditor
  15.   initEditor = () => {
  16.     this.editor = new E(this.editorRef.current);
  17.     this.editor.customConfig.onchange = (html) => {
  18.       console.log(html);
  19.       //? html 即变化之后的内容
  20.       this.editorRef.current.setFieldsValue({ content: html });
  21.     };
  22.     this.editor.create();
  23.   };
  24.  
  25.   componentDidMount() {
  26.     this.initEditor();
  27.   }
  28.   render() {
  29.     const onFinish = (values) => {
  30.       console.log("Received values of form: ", values);
  31.     };
  32.  
  33.     //? layout
  34.     const layout = {
  35.       labelCol: { span: 2 },
  36.       wrapperCol: { span: 14 },
  37.     };
  38.     return (
  39.       <Card title="编辑文章" extra={<Button>取消编辑</Button>}>
  40.         <Form
  41.           name="normal_article"
  42.           className="login-form"
  43.           initialValues={{ remember: true }}
  44.           onFinish={onFinish}
  45.           {...layout}
  46.         >
  47.           <Form.Item
  48.             name="content"
  49.             label="内容区域"
  50.             rules={[{ required: true, message: "内容不可为空" }]}
  51.           >
  52.             <div className="wangeditor-index" ref={this.editorRef}></div>
  53.           </Form.Item>
  54.           <Form.Item wrapperCol={{ offset: 2 }}>
  55.             <Button
  56.               type="primary"
  57.               htmlType="submit"
  58.               className="login-form-button"
  59.             >
  60.               保存修改
  61.             </Button>
  62.           </Form.Item>
  63.         </Form>
  64.       </Card>
  65.     );
  66.   }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement