search

Home  >  Q&A  >  body text

Problem with refreshing the custom ueditor editor in laravel-admin

I have defined the component in laravel-admin, it can be used, but it needs to be refreshed every time I use it.
When I click edit to enter, it will look like this, and it will only change when I refresh it. What the second picture looks like

I want to know how to change it directly to the picture in Chapter 2 without refreshing. . . .

The component is written like this, refer to the official document

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

<code class="php"><?php

namespace App\Admin\Extensions;

 

use Encore\Admin\Form\Field;

 

class UEditor extends Field

{

    protected $view = 'admin::form.editor';

    protected static $css = [

 

    ];

 

    protected static $js = [

       'vendor/ueditor/ueditor.config.js',

        'vendor/ueditor/ueditor.all.js',

    ];

 

    public function render()

    {

        $cs=csrf_token();

        $config=config('ueditor.route.name');

        $this->script = <<<EOT

          window.UEDITOR_CONFIG.serverUrl = '$config'

 var ue = UE.getEditor('{$this->id}');

    ue.ready(function() {

        ue.execCommand('serverparam', '_token', '$cs'); // 设置 CSRF token.

    });

   

EOT;

        return parent::render();

 

    }

}</code>

女神的闺蜜爱上我女神的闺蜜爱上我2846 days ago1566

reply all(1)I'll reply

  • phpcn_u1582

    phpcn_u15822017-06-16 09:21:36

    You should use vue, you should write ueditor as a component

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    17

    18

    19

    20

    21

    22

    23

    24

    25

    26

    27

    28

    29

    30

    31

    32

    33

    34

    35

    36

    37

    38

    39

    40

    41

    42

    43

    44

    45

    46

    47

    48

    49

    50

    51

    52

    53

    54

    55

    56

    <code><template>

      <p ref="editor"></p>

    </template>

     

    <script>

     

      import './ueditor.config';

      import './ueditor.all';

      import './lang/zh-cn/zh-cn';

     

     

      export default {

        data() {

          return {

            id: parseInt(Math.random()*1000)+'ueditorId',

          };

        },

        props: {

          value: {

            type: String,

            default: null,

          }

        },

        watch: {

          // value: function value(val, oldVal) {

          //   this.editor = UE.getEditor(this.id);

          //   if (val !== null) {

          //     this.editor.setContent(val);

          //   }

          // },

        },

        mounted() {

     

          var _this = this;

          this.$nextTick(function f1() {

            // 保证 this.$el 已经插入文档

     

            this.$refs.editor.id = this.id;

            this.editor = UE.getEditor(this.id, this.config);

     

            this.editor.ready(function f2() {

              this.editor.setContent(this.value==null?'<p></p>':this.value);

              this.editor.addListener("contentChange afterExecCommand", function () {

                const wordCount = _this.editor.getContentLength(true);

                const content = _this.editor.getContent();

                const plainTxt = _this.editor.getPlainTxt();

                _this.$emit('input', { wordCount: wordCount, content: content, plainTxt: plainTxt });

              }.bind(this));

     

              // this.$emit('ready', this.editor);

            }.bind(this));

          });

        },

      };

    </script>

    </code>

    reply
    0
  • Cancelreply