?生命周期執(zhí)行順序:
1、不使用keep-alive的情況:beforeRouteEnter --> created --> mounted --> destroyed
2、使用keep-alive的情況:beforeRouteEnter --> created --> mounted --> activated --> deactivated
3、使用keep-alive,并且再次進(jìn)入了緩存頁面的情況:beforeRouteEnter -->activated --> deactivated
在keep-alive頁面里的activated 監(jiān)聽路由的參數(shù)變化可以實現(xiàn)全頁面刷新,
?"$route.query.type": function name(paidrams) {
? ? ? ?if (this.$route.path === "當(dāng)前的路徑") {
? ? ? ? ?console.log("上次id", this.policyId, "本次id", this.$route.query.id);
? ? ? ? ?if (this.policyId != this.$route.query.id||this.pageType!= this.$route.query.type) {
? ? ? ? ? ?console.log("路由參變化");?
? ? ? ? ? ? ?this.getDetail();
? ? ? ? ?}
? ? ? ?}
? ? ?},
? ?$route: {
? ? ? ?handler: function (val, oldVal) {
? ? ? ? ?if (val.path === "當(dāng)前的路徑") {
? ? ? ? ? ?console.log("監(jiān)聽路由變化", val, oldVal);?
? ? ? ? ?}
? ? ? ?}
? ? ?}