亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

javascript - Under what circumstances is the component's life cycle beforeDestory triggered?
天蓬老師
天蓬老師 2017-07-05 10:46:40
0
2
1298

Can it be triggered when routing a jump? I found that the function in beforeDestory was not triggered when I made a route jump, but there was a piece of code that needed to be executed before the component was destroyed. What should I do?
https://jsfiddle.net/44w37p34/ A friend just sent me a demo. I found that his beforeDestory was triggered when the route jumped, but mine never worked. What is the reason?

天蓬老師
天蓬老師

歡迎選擇我的課程,讓我們一起見(jiàn)證您的進(jìn)步~~

reply all(2)
漂亮男人

I found the reason. I added a keep-alive to the router-view before, causing the component to be cached, so beforeDestory and destoryed will not be triggered

習(xí)慣沉默

I tried it, and it can trigger the execution of the beforeDestroy method when switching routes. The example is as follows.

const Home = {
        template: `
      <p>
      <p class="section">Some section foo</p>
      <p class="section">Some section foo</p>
      <p class="section">Some section foo</p>
      <p class="section">Some section foo</p>
    </p>
  `,
        mounted() {
           console.log("Home mounted");
        },
        beforeDestroy() {
            console.log("Home destroy");
        }
    };

    const Test = {
        template: `
            <p>
              <p class="section">Some section test</p>
              <p class="section">Some section test</p>
              <p class="section">Some section test</p>
              <p class="section">Some section test</p>
            </p>
  `,
        mounted() {
            console.log("Test mounted");
        },
        beforeDestroy() {
            console.log("Test destroy");
        }
    };
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template