Home >Web Front-end >Front-end Q&A >How to prevent vue from returning to the previous page
Vue prohibits returning to the previous page: 1. Install "vue-prevent-browser-back" through the "npm install vue-prevent-browser-back --save" command; 2. Use "import" "preventBack from..." method is introduced separately; 3. By adding the "mixins: [preventBack]" statement, you can prohibit returning to the previous page.
#The operating environment of this tutorial: Windows 10 system, Vue version 3, Dell G3 computer.
How to prevent return to the previous page in vue?
Simple method for Vue to prevent page rollback (applicable to browsers)
1. How to prevent page rollback?
After jumping to the page in VUE, there are many ways to prevent the page from returning. I will not list them all here. I use the vue-prevent-browser-back third-party library to prevent the page from returning. This The method is super easy to use.
2. Steps to use
1. Installation
The code is as follows:
npm install vue-prevent-browser-back --save
2.Introduction method
The code is as follows:
import preventBack from 'vue-prevent-browser-back';//组件内单独引入
3. Usage example
The code is as follows:
<script> import preventBack from &#39;vue-prevent-browser-back&#39;;//组件内单独引入 export default { name: '', props: {}, mixins: [preventBack],//注入 阻止返回上一页 components: {}, data() { return {}; }, computed: {}, watch: {}, methods: {}, created() {}, mounted() {} }; </script>禁止返回上级页面!
Summary
The above is today’s content, This article introduces the use of vue-prevent-browser-back. After introducing it into the component, add **mixins: [preventBack]** and it is completed. Is it simpler than other methods?
Recommended learning: "vue.js video tutorial"
The above is the detailed content of How to prevent vue from returning to the previous page. For more information, please follow other related articles on the PHP Chinese website!