react-codemirror2 编辑器需点击一下或者延时才显示数据的问题

现象:

<Codemirror/>组件的数据已经赋上值的情况下,初始状态不渲染数据,需要点击编辑框获取焦点后才展示,或者延迟了几秒才显示出来。

原因:

指定了一些依赖的版本,可能不兼容了一些功能,导致这个现象出现

解决:

  1. 手动引入自动刷新的插件;

2.配置一下参数

代码如下:

TypeScript 复制代码
import {UnControlled as CodeMirror} from 'react-codemirror2';
import 'codemirror/lib/codemirror.css';
import 'codemirror/mode/sql/sql'; 
...
// 引入自动刷新
import 'codemirror/addon/display/autorefresh'


<CodeMirror 
    value={format(code,{lanuage:'plsql'})} 
    options={
        autoRefresh: true, // 重点是这句,为true

        scrollbarStyle: null,
        mode: 'text/x-pgsql',
        theme: 'material',
        autofocus: false,
        readOnly: false,
        lineNumbers: true, 
        smartIndent: true,
        lint: true,
        lintWrapping: true
        
   } 
    onChange={(editor,data,value)=>{...}}
>
</CodeMirror>

 

官网:https://github.com/uiwjs/react-codemirror

codemirror2编辑器总结

相关推荐
hgz0710几秒前
企业级多项目部署与Tomcat运维实战
前端·firefox
zhoumeina991 分钟前
懒加载图片
前端·javascript·vue.js
用户1887871069842 分钟前
SVG描边 - CSS3实现动画绘制矢量图
前端
码上行走3 分钟前
【实战】Flex布局-上下自适应
前端
DarkLONGLOVE3 分钟前
Vue的“小外挂”:玩转自定义指令
前端·javascript·vue.js
ccino .4 分钟前
pdf-xss文件制作过程
前端·pdf·xss
yuniko-n6 分钟前
【MySQL】通俗易懂的 MVCC 与事务
数据库·后端·sql·mysql
崇山峻岭之间8 分钟前
Matlab学习记录06
前端·学习·matlab
半兽先生8 分钟前
微信小程序与web-view页面双向通信
前端·微信小程序·小程序
西西学代码9 分钟前
Flutter---常用打印图标
前端·python·flutter