0

I am using Vue2Editor and would like to insert image from url but the default option loads image from local machine. Is there a way to insert a link to image, not select from local machine?

I tried to something on @image-added but is called after selecting event on machine.

Here is link to the editor: https://github.com/davidroyer/vue2-editor

1 Answer 1

2
<template>
  <div id="app">
    <vue-editor use-custom-image-handler @image-added="handleImageAdded" v-model="data[dataItem + lang.code]" :editorOptions="editorSettings"></vue-editor>
  </div>
</template>

<script>
import { VueEditor,Quill } from 'vue2-editor'
import axios from "axios";
import ImageResize from 'quill-image-resize-vue';
import { ImageDrop } from 'quill-image-drop-module';

Quill.register("modules/imageDrop", ImageDrop);
Quill.register("modules/imageResize", ImageResize);

export default {
  name: 'Editor',
  components: {
    VueEditor
  },
  props: ['data', 'lang', 'dataItem'],
  data() {
    return {
      htmlForEditor: "",
      editorSettings: {
        modules: {
          imageDrop: true,
          imageResize: {},
        }
      }
    };
  },

  methods: {
    handleImageAdded: function (file, Editor, cursorLocation, resetUploader) {
      var formData = new FormData();
      formData.append("file", file);
      var vuex = window.localStorage.getItem('vuex')
      var token = JSON.parse(vuex);

      axios({
        url: this.base_url + "/file/fileupload",
        method: "POST",
        data: formData,
        headers: {'Authorization': 'Bearer ' + token.auth.userToken}
      }).then(result => {
        let url = result.data.filePath; // Get url from response
        Editor.insertEmbed(cursorLocation, "image", url);
        resetUploader();
      }).catch(err => {
        alert('yukleme basarisiz! ' + err)
      });
    }
  }
};
</script>
Sign up to request clarification or add additional context in comments.

1 Comment

Welcome to StackOverflow. While this code may solve the question, including an explanation of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please edit your answer to add explanations and give an indication of what limitations and assumptions apply.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.