slatejsx
1.0.0
npm install slatejsxhttp://seditor.open.heyphp.com
import SEditor from 'slatejsx' ;
import 'slatejsx/dist/index.css' ;
import { useState } from 'react' ;
const config = [
{
"type" : "paragraph" ,
"title" : "h1" ,
"children" : [
{
"text" : ""
}
]
}
]
const [ value , setValue ] = useState ( config )
// 上传图片的回调,示例中将图片转为base64写入json,如果需要存到云存储可以改写此方法
const onUploadImage = ( file , callback ) => {
const reader = new FileReader ( ) ;
reader . addEventListener ( 'load' , ( ) => {
const url = reader . result ;
callback ( url )
} ) ;
reader . readAsDataURL ( file ) ;
}
function App ( ) {
return (
< SEditor
value = { value }
plugins = { [ ] }
readOnly = { false }
param = { { onUploadImage } }
onChange = { v => setValue ( v ) }
/>
) ;
}
export default App ; | parámetro | tipo | ilustrar |
|---|---|---|
| valor | formación | Consulte la documentación oficial de SlateJS, puede inicializar la estructura en el ejemplo. |
| en el cambio | función | Devoluciones de llamada Cuando cambia los datos, consulte el ejemplo anterior |
| complementos | formación | Complemento adicional, si necesita agregar nuevas funciones del editor, puede pasarlo a través de este parámetro. |
| readonamente | booleano | De solo solo lectura, si es cierto, no hay una barra de herramientas y no se puede editar |
| parámetro | {} | Parámetros adicionales, los parámetros se escribirán en la entidad de usoslate () |