Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

159
Vistas
Vue 3 and TipTap Editor pass in global scope

I'm working in VueJS 3 and just added the TipTap Editor. I want to only show the editor menu when the user clicks on the content, firing the focus event. Then on blur the menu needs to be hidden. So I added a ref="myMenu" to the menu component and init the editor with opFocus nad onBlur event handlers.

Problem, "this" is referencing the scope of the Editor and not the "this" that knows about the $refs. Question, how do I pass in the global properties?

my template

        <div v-if="editor">
            <menu-bar class="editor__header" :editor="editor" ref="editMenu" />
            <editor-content :editor="editor" />
        </div>

my vue code

    mounted(){
    // this.store.methods.TextAreaAdjust(this.$refs.itemParagraph);
       
    this.editor = new Editor( {
        extensions: [ 
          StarterKit.configure({
           history:true,
          }),
          Highlight,
       ],
        content: this.modelValue.itemData.paragraph,
        onUpdate: () => {
          this.modelValue.itemData.paragraph=this.editor.getHTML()
        },

        onFocus(){
            console.log('focus fired')
            console.log(this) // editor scope
            this.$refs.editMenu.style.display="flex" // $refs undefined error
        },
        onBlur(){
            console.log('blur fired')
            this.$refs.editMenu.style.display="none"
        }

    })
},
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Try to define the on functions with arrow functions:

onUpdate: () => {}
ononFocus: () => {}
onBlur: () => {}

This should keep the this scope.

Else you probably need to store this in a separate const, before you create the Editor instance and then use thisComponent in your handlers:

const thisComponent = this;
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda