insertText () в компоненте ckeditor для Vue.js - PullRequest
0 голосов
/ 15 марта 2019

Я пытаюсь интегрировать ckeditor 5 в мое приложение vue js. Я успешно добавил ckeditor, но теперь я хочу добавить некоторый текст в позиции курсора в ckeditor по нажатию кнопки.Поэтому, чтобы добиться этого, я попробовал метод insertText .Но я не могу получить экземпляр редактора в vue при добавлении кода как editor.model.change (...)

Uncaught ReferenceError: editor is not defined

Code =>

<template>
  <ckeditor
    id="custom"
    ref="custom"
    name="custom"
    :editor="editor"
    :config="editorCustomConfig"
    v-model="message">
  </ckeditor>
  <a href="#" @click="addCodeInMsg">Add Text In Editor</a>
</template>
<script>
import ClassicEditor from "@ckeditor/ckeditor5-build-classic";
export default {
  name: "topbar",
  },
  data() {
    return {
       editor: ClassicEditor,
       editorConfig: {
       },
       message:''
    };
  },
  methods: {
    addCodeInMsg(e){
      editor.change( writer => {
        const insertPosition = editor.model.document.selection.getFirstPosition();
        writer.insertText( 'CKEditor 5 rocks!', { linkHref: 'https://ckeditor.com/' }, insertPosition );
      } );
    }
  }
</script>

Я не знаю, чего мне не хватает при использовании компонента ckeditor. Буду признателен за любую помощь.

1 Ответ

0 голосов
/ 15 марта 2019

забыл про это :

methods: {
    addCodeInMsg(e){
      this.editor.change( writer => {
        const insertPosition = this.editor.model.document.selection.getFirstPosition();
        writer.insertText( 'CKEditor 5 rocks!', { linkHref: 'https://ckeditor.com/' }, insertPosition );
      } );
    }
  }
...