Aksix
Aksix

Reputation: 41

how to manually render data from editor-js

I'm using editor.js for the first time, and I got stuck on this part: After selecting image from my gallery I want to re-render editor js with new image: this is my code for now

let url = `/${this.selectedImg.image.id}/${this.selectedImg.image.name}`
  this.editor.configuration.data.blocks.push({
    data: {
      caption: "",
      file: {url: url},
      stretched: false,
      withBackground: false,
      withBorder: false,
    },
    type: "image"
  })
  console.log(this.editor,'editor')
  this.editor.render()

but this.editor.render() doesn't work, what am I missing? this is console.log screenshot

I would appreciate any help!

Upvotes: 2

Views: 2940

Answers (1)

Aksix
Aksix

Reputation: 41

 editor.save().then((data) => {
     data.blocks.push({
       type: "image",
       data: {
         caption: "",
         file: {url: url},
         stretched: false,
         withBackground: false,
         withBorder: false,
       },
     })
     this.editor.render(data)
     this.$emit('close', true)
   })

this was the answer, I misread the docs :)

Upvotes: 2

Related Questions