Vue js rerender the same component when changing route

后端 未结 3 590
故里飘歌
故里飘歌 2020-12-15 23:12

I have one auth component that I am using both in the login and the signup route.

const routes = [{
  path     : \'/\',
  name: \'home\',
  component: Home
}         


        
3条回答
  •  有刺的猬
    2020-12-15 23:32

    vuejs caches rendered component. you don't provide Auth component code, but i think the following helps you.

    
    export default {
        name: 'Auth',
        //component code .....
        data: function() {
            return {
                usernameinput: '',
                //and other stuff
            }
        },
        watch: {
            // call method if the route changes
            '$route': 'reInitialize'
        },
        methods: {
            reInitialize: function() {
                this.usernameinput = '';
                //and so on
            }
        },
        //remainig component code
    }
    

    also there is another posibilty, may be you are using dynamic components and keep-alive is true.

提交回复
热议问题