当前位置:网站首页>After login, the upper right corner changes to enter the login status

After login, the upper right corner changes to enter the login status

2022-07-28 04:23:00 My name is Lili

adopt currentUser The value of the inside   If there is value in it, enter   Login to the displayed component   If there is no value, the unregistered components will be displayed

First step :

adopt mapState    // Get to login login Inside currentUser, Then give to Menu

meanwhile   reducer Inside user    login The warehouse also adds a field currentUser:initUser(),

If you don't let him in the next time you come in, it's empty   stay reducer Inside user    login Warehouse write one initUser Method   Get... Locally user

const initUser=()=>{

    // Get user information locally

    const currentUser=getData('currentUser')

    if (currentUser) {

        return currentUser

    }

    return null

}

In this way, we can Menu  Yes props adopt currentUser The value of the inside   If there is value in it, enter   Login to the displayed component   If there is no value, the unregistered components will be displayed

currentUser It will also read values from the local cache   stay reducer  login Inside .( adopt initUser Method )

Second point

Login emptying and registration are the same    reducer Re value inside

Write the settings

Build a page with exit and update functions

原网站

版权声明
本文为[My name is Lili]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/209/202207280421289153.html