The scope of JS Code of vue single File component

this is the JS code for Index.vue, but when I router-link to another component, the js code for Index.vue executes again. How to make the JS code of each component only for your own use?

Mar.13,2021

normally the js code of each component is used internally, unless you bind a global event like window.scroll, and do not destroy this event when you leave the route, it will lead to the situation that other pages will still execute.

Menu