vue-editor-js icon indicating copy to clipboard operation
vue-editor-js copied to clipboard

TypeError: _this.$refs.editor.save is not a function

Open MuhammadNFadhil opened this issue 4 years ago • 3 comments

When I press the save button it shows me the error message: TypeError: _this.$refs.editor.save is not a function... My vue view code:

<template>
  <div class="home">
    <editor
      header
      list
      code
      ref="editor"
      autofocus
      holder-id="codex-editor"
      save-button-id="save-button"
      @save="onSave"
      :config="config"
    />
    <button @click="save">Save!</button>
  </div>
</template>

<style lang="scss" scoped></style>

<script>
export default {
  name: "CreatePost",
  data() {
    return {
      config: {
        image: {
          field: "image",
          types: "image/*",
        },
      },
    };
  },
  methods: {
    onSave(response) {
      console.log("response: ", response);
    },
    async save() {
      const res = await this.$refs.editor.save();
      console.log("res: ", res);
    },
  },
};
</script>

MuhammadNFadhil avatar Dec 14 '20 12:12 MuhammadNFadhil

I found a workaround https://github.com/ChangJoo-Park/vue-editor-js/blob/master/demo/Demo.vue#L101 args from onChange has saver, so saver.save() gives me the content of editor :)

zghib avatar Dec 18 '20 07:12 zghib

Is there any new solution out there? I got two different property saver and save but that's not working also.

SharedScreenshot

bidyut18 avatar Dec 29 '20 18:12 bidyut18

Use this :

this.$refs.editor._data.state.editor.save()

also the useful render() is on this path

xfhg avatar Feb 13 '21 13:02 xfhg