在使用百度编辑器时,默认有一个自动保存的功能,但是重新刷新页面或者退出当前登陆用户再次进来的时候,不会显示具体内容。从网上找了很多的贴子发现,都是说取消改功能。即:

在euditor.config.js中把enableAutoSave: false关闭该功能。

怎么好的功能为什么要关闭,于是去查找官方文档http://fex.baidu/ueditor/发现。有可以获取草稿箱内容的方法,在本

地使用后失效。经过研究发现,当页面刷新的时候全先加载JS后加载编辑器所在div或者textarea,我们修改方法如下:

<div class="form-group {!! !$errors->has($errorKey) ?: 'has-error' !!}">
    <label for="{{$id}}" class="col-sm-2 control-label">{{$label}}</label>
    <div class="col-sm-8">
        @include('admin::form.error')
        {{-- 这个style可以限制他的高度,不会随着内容变长 --}}
        <textarea type='text/plain' style="height:400px;" id='ueditor' id="{{$id}}" name="{{$name}}"
                  placeholder="{{ $placeholder }}" {!! $attributes !!}  class='ueditor'>
            {!! old($column, $value) !!}
        </textarea>
        @include('admin::form.help-block')
    </div>
</div>

<script type="text/javascript">
    $(document).ready(function () {
        setTimeout(ueget,1000);
    })
    function ueget() {
        var ue = UE.getEditor("ueditor", {initialFrameHeight:340,initialFrameWidth:760,maximumWords:1000,autoHeightEnabled:false});
        ue.ready(function() {
            var html = ue.getContent();
            if(html =='' || html =='undefined'){
                console.log('editor is null');
                ue.execCommand('drafts');
            }else{
                console.log('editor not null');
            }
        });

    }
</script>

原理:页面刷新延时1秒去获取缓冲文件,并为其设置宽高,字数。参数可根据 自己的需求进行设置。

缓冲文件会保存在本地local storage里。


更多推荐

百度编辑器UEditor自动保存实现