Tui.editor: How to get the content from editor?

Created on 20 Mar 2020  路  4Comments  路  Source: nhn/tui.editor

I use the vue wrapper of editor in my application.
I have try

console.log(this.$refs.editor.getHtml);

But every time the console prints "undefined".

How can I get the content in the editor correctly?

Question

Most helpful comment

@Rorke76753 What you called above is to check the existence of the method, so the usage is wrong. When getting the value entered in the current editor, the following instance method should be called.

<template>
  <div>
    <button v-on:click="getMarkdown">getMarkdown</button>
    <button v-on:click="getHtml">getHtml</button>
    <editor ref="toastuiEditor" />
  </div>
</template>

<script>
import 'codemirror/lib/codemirror.css';
import '@toast-ui/editor/dist/toastui-editor.css';

import { Editor } from '@toast-ui/vue-editor';

export default {
  components: {
    editor: Editor
  },
  methods: {
    getMarkdown() {
      let markdown = this.$refs.toastuiEditor.invoke('getMarkdown');

      console.log(markdown);
    },
    getHtml() {
      let html = this.$refs.toastuiEditor.invoke('getHtml');

      console.log(html);
    }
  }
};
</script>

vue-editor

All 4 comments

@Rorke76753 What you called above is to check the existence of the method, so the usage is wrong. When getting the value entered in the current editor, the following instance method should be called.

<template>
  <div>
    <button v-on:click="getMarkdown">getMarkdown</button>
    <button v-on:click="getHtml">getHtml</button>
    <editor ref="toastuiEditor" />
  </div>
</template>

<script>
import 'codemirror/lib/codemirror.css';
import '@toast-ui/editor/dist/toastui-editor.css';

import { Editor } from '@toast-ui/vue-editor';

export default {
  components: {
    editor: Editor
  },
  methods: {
    getMarkdown() {
      let markdown = this.$refs.toastuiEditor.invoke('getMarkdown');

      console.log(markdown);
    },
    getHtml() {
      let html = this.$refs.toastuiEditor.invoke('getHtml');

      console.log(html);
    }
  }
};
</script>

vue-editor

@Rorke76753 What you called above is to check the existence of the method, so the usage is wrong. When getting the value entered in the current editor, the following instance method should be called.

<template>
  <div>
    <button v-on:click="getMarkdown">getMarkdown</button>
    <button v-on:click="getHtml">getHtml</button>
    <editor ref="toastuiEditor" />
  </div>
</template>

<script>
import 'codemirror/lib/codemirror.css';
import '@toast-ui/editor/dist/toastui-editor.css';

import { Editor } from '@toast-ui/vue-editor';

export default {
  components: {
    editor: Editor
  },
  methods: {
    getMarkdown() {
      let markdown = this.$refs.toastuiEditor.invoke('getMarkdown');

      console.log(markdown);
    },
    getHtml() {
      let html = this.$refs.toastuiEditor.invoke('getHtml');

      console.log(html);
    }
  }
};
</script>

vue-editor

Thank you , this help me a lot.

image
why i get no content but a empty string

Is there such a way to get content? I remember I didn't do it that way

editor.getMarkdown()

https://github.com/jackworkshop/WP-ReliableMD/blob/master/js/WPReliableMD_Admin.js#L240-L250

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bricepepin picture bricepepin  路  3Comments

hrvoj3e picture hrvoj3e  路  3Comments

Gilles-GitHub picture Gilles-GitHub  路  4Comments

Yeongjae-Shin picture Yeongjae-Shin  路  3Comments

tirli picture tirli  路  5Comments