Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

66
Views
Vue 3 Acceso a un elemento DOM antes del montaje

Estoy creando un componente Vue <Link> dentro de NuxtJS con la nueva sintaxis API de composición. Me gustaría configurar automáticamente el color de mi UiIcon cuando la raíz de la plantilla tiene la clase disabled .

Primero pensé en este enfoque, pero luego me di cuenta de que en el método de configuración, el DOM aún no estaba accesible. ¿Cuál podría ser otra solución viable?

PD: Logré resolverlo usando el atributo de stroke CSS porque UiIcon es un SVG, pero tenía curiosidad por saber si había otra solución que utilizara el color pop ya definido.

 <template> <div ref="row" class="row"> <UiIcon v-if="linkIcon" :type="linkIcon" :color="linkIconColor" class="icon" /> <a class="link" :href="linkHref" :target="linkTarget" :rel="linkTarget === 'blank' ? 'noopener noreferrer' : null" @mouseover="linkActive = true" @mouseout="linkActive = false" > <slot></slot> </a> </div> </template> <script lang="ts"> import { defineComponent, computed, ref, toRefs, } from '@nuxtjs/composition-api'; import { Colors } from '~/helpers/styles'; export default defineComponent({ name: 'Link', props: { href: { type: String, default: undefined, }, target: { type: String as () => '_blank' | '_self' | '_parent' | '_top', default: '_self', }, icon: { type: String, default: undefined, }, iconColor: { type: String, default: undefined, }, iconHoverColor: { type: String, default: undefined, }, }, setup(props) { const { href, target, icon, iconHoverColor } = toRefs(props); const linkActive = ref(false); const row = ref<HTMLDivElement | null>(null); const linkIconColor = computed(() => { const linkDisabled = row.value?.classList.contains('disabled'); if (linkDisabled) { return Colors.DARK_GREY; } if (linkActive.value && iconHoverColor.value) { return props.iconHoverColor; } return props.iconColor; }); return { linkHref: href, linkTarget: target, linkIcon: icon, linkIconColor, linkActive, }; }, }); </script>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

De acuerdo con la documentación de Vue, beforeUpdate es un buen lugar para acceder al elemento DOM antes del gancho actualizado. Sin embargo, también puede usar $nextTick para acceder al DOM dentro de beforeMount.

 beforeMount() { this.$nextTick(function () { //code here }) }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!