vue 路由參數變化,頁面不更新的問題


 

監控$route

在vue項目中,假使我們在同一個路由下,只是改變路由后面的參數值,如果不監聽路由參數值的變化,頁面無數據刷新,需手動刷新瀏覽器,這樣做就不是我們的預期效果。

舉例:當前路由為  /pjthome?pjtid=123456

mounted: function () {
this.pjtid = this.$route.query.pjtid
this.pjtdetail()
},
在頁面pjtdetail()方法中,需要用到pjtid這個參數,假如在同一頁面有相似項目切換,只是pjtid發生變化,在切換時,並未重新加載數據,原因是跟vue的生命周期有關,具體該解決這個問題,添加路由監聽即可。

exp:

watch: {
$route(){
this.pjtid = this.$route.query.pjtid
},
pjtid() {
this.pjtdetail()
},
}
解決。
---------------------
作者:酷酷小七
來源:CSDN
原文:https://blog.csdn.net/weixin_37861326/article/details/80525720
版權聲明:本文為博主原創文章,轉載請附上博文鏈接!

 

如:

<script>
    export default {
        data() {
            return {
                isApp: true,
            }
        },
        mounted() {
            this.caseId = this.$route.query.caseId;
            this.isApp = (this.$route.query.type == 'APP定制') ? true : false;
        },
        methods: {
            getIsApp() {
                this.isApp = (this.$route.query.type == 'APP定制') ? true : false;
            }
        },
        watch: {
            $route(){
                this.isApp = this.$route.query.type;
            },
            isApp() {
                this.getIsApp();
            },
        }
    }
</script>

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM