About passing values between pages of vue,$router

problem description

A new one is cute. Now when we practice VUE, we will encounter the problem of passing values between pages, using the method of passing values through $router

give me a chestnut

A page passes
this.$router.push ({path:"/adminManage",query: {usn:result.data}})

B page acquisition (search method used)
post a link
https://blog.csdn.net/hanxion...

created:function(){ 
    this.getParams();
},
watch: { 
// ,
      "$route": "getParams"
},
methods:{ 
    getParams:function(){ // 
        var routerParams = this.$route.query.nameId // 
    console.log("=="+routerParams) 
    this.textareText = routerParams 
    },
}

later I tried to assign values directly in data of B page

data(){
        return{
            role:this.$route.query.usn.role
        }
    },

found that it is fine without listening, but in line with the idea that the boss"s method is probably better than his own, I would like to ask you: what is wrong with my practice

cheeky

ask the bosses to advise you about the scenarios in which the page passes the value of $router,eventBus and Storage

.

really doesn't need to listen, because the route only changes once.
eventBus is suitable for relatively simple scenarios, storing some global methods and objects, etc. Storage can be divided into two types, sessionStorage and localStorage, which are used for browser storage.
as for passing values between pages, it is better to use the $router object.


$router is applicable to values passed between pages, such as details pages, etc.
eventBus is applicable to values passed between peers, such as two peer modules.
Storage is suitable for global value passing, and is generally used as a cache, which can be used either between pages or at the same level. However, the disadvantage is that the cached data occupies resources


1, and the value passed by the route can be obtained without monitoring.
2, $router is suitable for passing some simple values that have nothing to do with the state
3, eventBus is used when you tell someone when something is done
4, Storage. Data that needs to be persisted, data used by multiple pages, and large data

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3415e-2bed9.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3415e-2bed9.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?