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

162
Vistas
Why the button stays always hidden?
<div class="app__land-bottom" v-if="isVisible">
  <a href="#projects">
    <img ref="arrowRef" id="arrow" src="./../assets/down.png" alt srcset />
  </a>
</div>

In Vue3 setup isn't working, but on Vue2 is working the following solution for not displaying a button based on scrolling.

VUE3
<script setup>
import { ref, onMounted, onUnmounted } from "vue";

let isVisible = ref(false);

onMounted(() => {
  window.addEventListener("scroll", () => {
    hideArrow();
  });
});

onUnmounted(() => {
  window.removeEventListener("scroll", () => {
    hideArrow();
  });
});

const hideArrow = () => {
  const currentScroll = window.pageYOffset;
  if (currentScroll > 100) {
    isVisible = false;
  } 
  else if (currentScroll < 100) {
    isVisible = true;
  }
}
</script>
VUE2
<script>
export default {
  created() {
    window.addEventListener('scroll', this.hideArrow)
  },
  data() {
    return {
      isVisible: false, 
    }
  },
  methods: {
    hideArrow() {
      const currentScroll = window.pageYOffset;
      if (currentScroll > 100) {
        this.isVisible = false;
      } else if (currentScroll < 100) {
        this.isVisible = true;
      }
    },
  },
}
</script>

In vue2 the solution is working but on Vue3, not. Any suggestions? I don't understand exactly where the problem is? It would be helpful an answer.

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

0

when mutating your ref: isVisible you need to type: isVisible.value instead of isVisible

your hideArrow function should be:

const hideArrow = () => {
  const currentScroll = window.pageYOffset;
  if (currentScroll > 100) {
    isVisible.value = false;
  } 
  else if (currentScroll < 100) {
    isVisible.value = true;
  }
}

for more details: check Ref docs in Vue

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