Element ui navigation bar select background color refresh disappears
<el-menu :is-collapse="isCollapse" text-color="#fff" active-text-color="#fff" :default-active="activerouter" :router="true" > </el-menu> //The point is:default-active="activerouter"Settings
Hang in data
data() { return:activerouter; }
mounted() { = //Under normal circumstances, this sentence can be solved. If it cannot be solved, continue reading. },
2. Add a click event to menuItem, and the routing address is used as a parameter
<el-menu-item :index="" class="active_bg" :class="{ active_bg: index == activeIndex }" @click="selectMenuItem()" > </el-menu-item>
3. Save the obtained route address locally
selectMenuItem(path) { = path ("activerouter", path); },
4. Note that the mounted() is written as follows, so don’t use it again.
mounted() { //Get the route in the address bar and set the navigation bar selection status in elementui = ("activerouter"); ('activerouter',) },
Select Highlight in the Element ui navigation bar, and select Disappear after refreshing
Side menu
After selecting the navigation bar, refreshing the page will find that the selected navigation bar highlights have disappeared, or jumped to other options. The idea here is to define the method, store the route into sessionStorage, and get it from sessionStorage when the page is reloaded.
<!--Side menu--> <el-menu :default-active="active" class="el-menu-vertical-demo" router> <router-link to="/user" style="text-decoration: none"> <el-menu-item index="/user" v-if="isflag" @click="selectMenuItem('/user')"> <el-icon><User /></el-icon> <span>User Information</span> </el-menu-item> </router-link> <el-menu-item index="order" v-if="isflag" @click="selectMenuItem('order')"> <el-icon><Tickets /></el-icon> <span>Order Management</span> </el-menu-item> <el-menu-item index="manage" v-if="=='op' ? false : true" @click="selectMenuItem('manage')"> <el-icon><Reading /></el-icon> <span>Task Management</span> </el-menu-item> <el-menu-item index="task" v-if="isflag" @click="selectMenuItem('task')"> <el-icon><Calendar /></el-icon> <span>Schedule</span> </el-menu-item> </el-menu>
data() { return { active: "/user", }; },
mounted(){ = ("activerouter"); },
methods: { selectMenuItem(path) { = path ("activerouter", path); }, }
Summarize
The above is personal experience. I hope you can give you a reference and I hope you can support me more.