No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    how to insert image in Editor (WYSIWYG)

    Help
    5
    7
    5030
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D
      donvie last edited by

      Editor (WYSIWYG)

      1 Reply Last reply Reply Quote 1
      • M
        Max last edited by Max

        register the component and use it in your template…

        all explained here: QEditor

        D 1 Reply Last reply Reply Quote 0
        • D
          donvie @Max last edited by

          @max how to upload image?

          1 Reply Last reply Reply Quote 0
          • M
            Max last edited by Max

            check: qeditor-definitions . allows to specify a handler for upload as an example

            1 Reply Last reply Reply Quote 0
            • CristalT
              CristalT last edited by CristalT

              You have to set definitions property:

              <!-- HTML -->
              <q-editor v-model="post.body" :definitions="definitions"/>
              
              
              // script
              
              data() {
                  return {
                      definitions: {
                              insert_img: {
                                  tip: 'Insertar Imagen',
                                  icon: 'photo',
                                  handler: this.insertImg // handler will call insertImg() method
                              }
                          }
                      }
                  },
                  methods: {
                      insertImg() { // insertImg method
                          const post = this.post
                          // create an input file element to open file dialog
                          const input = document.createElement('input')
                          input.type = 'file'
                          input.accept = '.png, .jpg' // file extensions allowed
                          let file
                          input.onchange = _ => {
                              const files = Array.from(input.files)
                              file = files[0]
                
                             // lets load the file as dataUrl
                              const reader = new FileReader()
                              let dataUrl = ''
                              reader.onloadend = function() {
                                  dataUrl = reader.result
                                 
                                  // append result to the body of your post
                                  post.body += '<div><img src="' + dataUrl + '" /></div>' 
                              }
                              reader.readAsDataURL(file)
                          }
                          input.click()
                      }
              }
              
              qyloxe 1 Reply Last reply Reply Quote 2
              • R
                rv last edited by rv

                Would it be possible to paste image in q-editor using Ctrl+V or drag-and-drop?

                1 Reply Last reply Reply Quote 0
                • qyloxe
                  qyloxe @CristalT last edited by

                  @cristalt said in how to insert image in Editor (WYSIWYG):

                  post.body += '<div><img src="' + dataUrl + '" /></div>' 
                  

                  You can replace above with this. It puts the image in cursor position:

                  document.execCommand('insertHTML', true, '<div><img src="' + dataUrl + '" /></div>')
                  
                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post