Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Calculator

0

42
Views
How to ask user to confirm page refresh in vue3 composition API

I am new ti Vue and I am trying to get my app to ask the user for confimration before a page refresh (manual) can be done. IS this possible?

I know how to get the confirmation when the user clicks another router link.

I used the example here enter link description here to create this :

import { useRouter, onBeforeRouteLeave } from "vue-router";
    const promptExit = ref(true);
   onBeforeRouteLeave((to, from, next) => {
      if (promptExit.value) {
        const answer = window.confirm('Do you really want to leave? you have unsaved changes!')
  if (answer) {
    from()
  } else {
    from(false)
  }
      } else {
        next();
      }
    });

But is there a way to have the same effect on a hard page refresh on the browser

7 months ago ยท Juan Pablo Isaza
Answer question
Find remote jobs