国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

通過vue刷新左側菜單欄操作

瀏覽:110日期:2022-12-15 10:08:16

今天完成了手頭任務就想著做點什么,剛好領導讓我看看項目左側菜單欄不刷新的問題,我也是剛剛接觸vue,很多東西都還不是很熟練,這也是我的第一篇自己寫的博客,感覺還是很興奮的,我覺得寫博客這個習慣要一直養成,不但總結了自己一天的工作所得,而且也是對自己的一種良好習慣的養成。

下面進入正題。

這個是我們html里面的超鏈接,而我們的點擊事件的跳轉就是通過這個超鏈接實現的。

<el-menu-item index='3-1'><a href='http://www.cgvv.com.cn/bcjs/11103.html#/commodity-list' rel='external nofollow' >

然后我們要創建一個js文件,將我們要跳轉的路徑導入

import ChannelList from ’./src/commodity-manage/channel-list/channel-list’

配置路由管理:

const router = new VueRouter({ routes: [ { path: ’/commodity-list’, name: ’commodity-list’, component: commodityStorage, children: [] }]

path:就是我們要跳轉的路徑

name:跳轉文件的名字

component:配置了映射的組件

在html文件中配置了<router-view/>

<router-view :key='key'></router-view>

是用來渲染通過路由映射過來的組件,當路徑更改時,<router-view> 中的內容也會發生更改

在js文件中使用computed來進行監聽

//每次讓路由生成不同的值,用于重新加載組件,達到刷新數據的效果 computed: { key() { return this.$route.name !== undefined? this.$route.name +new Date(): this.$route +new Date() } },

補充知識:vue:路由菜單(element 和 antd)

在 vue 中 使用 UI框架中的菜單,給菜單如何添加路由呢?其中會出現路由樣式的問題。請看下面兩種UI方法。

注)使用框架的時候注入知道的吧。。。。。防止有些人xxxx,我還是寫一下。

通過vue刷新左側菜單欄操作

場景:使用 elementUI 的 NavMenu 時。

這里請注意:可以不使用 router-link,在 e-menu 上面綁定 route 或者 :route = ’true’ ,然后遍歷的時候 :index=‘route.path’ (:index=‘路徑’)。

通過vue刷新左側菜單欄操作

代碼

<template> <div class='menu'> <el-menu default-active=’activePath’ router @open=’handleOpen’ @close=’handleClose’ background-color=’#545c64’ text-color=’#fff’ active-text-color=’#ffd04b’ > <template v-for='(route,index) in routes'><!-- 一級菜單 --><el-menu-item :key=’index’ v-if=’route.children && route.children.length== 1’ :index=’route.path’> <i :class='’el-icon-’ + route.meta.icon'></i> <span>{{route.meta.title}}</span></el-menu-item> <!-- 二級菜單 --><el-submenu v-if=’route.children && route.children.length > 1’ :key=’index’ :index=’route.path’> <template slot=’title’> <i :class='’el-icon-’ + route.meta.icon'></i> {{route.meta.title}} </template> <el-menu-item-group v-for=’(item, index) in route.children’> <el-menu-item :key=’index’ :index=’resolve(route.path, item.path)’> <i :class='’el-icon-’ + item.meta.icon'></i> {{item.meta.title}} </el-menu-item> </el-menu-item-group></el-submenu> </template> </el-menu> </div></template> <script> export default { name: ’Menu’, data() { return { activePath: this.$router.path, } }, computed: { // 計算屬性:獲取路由 routes() { console.log(’test’, this.$router) console.log(’ddd’, this.$router.options.routes) return this.$router.options.routes }, }, methods: { resolve(p,i){ return `${p}/${i}` }, handleOpen(key, keyPath) { console.log(key, keyPath); }, handleClose(key, keyPath) { console.log(key, keyPath); } },}</script> <style lang=’less’> .el-menu { text-align: left; }</style>

場景:使用 antd 的 Menu 時。

這個里面是需要使用route-link做路由跳轉的。

通過vue刷新左側菜單欄操作

代碼

<template> <div class='menu'> <a-menu v-model='current' mode='inline' theme='dark'> <template v-for=’route in routes’> <!-- 一級菜單 --> <a-menu-item v-if=’route.children && route.children.length == 1’ :key=’route.path’><router-link :to=’route.path’> <a-icon :type=’route.meta.icon’ /> {{ route.meta.title }}</router-link> </a-menu-item><!-- 二級菜單 --> <a-sub-menu v-else=’route.children && route.children.length == 2’ key='sub1'><span slot='title'><span><a-icon :type=’route.meta.icon’ />{{ route.meta.title}}</span></span><a-menu-item v-for=’item in route.children’ :key=’item.path’> <router-link :to=’resolve(route.path,item.path)’> <!-- <router-link :to='`${route.path}/${item.path}`'> --> <a-icon :type=’item.meta.icon’ /> {{ item.meta.title }} </router-link></a-menu-item> </a-sub-menu> </template> </a-menu> </div></template> <script> export default { name: ’Menu’, data() { return { current: [’/’], } }, computed: { // 計算屬性:獲取路由 routes() { console.log(’test’, this.$router) console.log(’ddd’, this.$router.options.routes) return this.$router.options.routes }, }, methods:{ resolve(p,i){ return `${p}/${i}` }, },}</script>

以上這篇通過vue刷新左側菜單欄操作就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持好吧啦網。

標簽: Vue
相關文章:
主站蜘蛛池模板: 成人精品视频一区二区在线 | 欧美jizzhd精品欧美 | 久久亚洲人成国产精品 | 免费视频一区二区 | 日韩 欧美 中文 亚洲 高清 在线 | 国产三级麻豆 | 成人a在线 | 久草在线资源视频 | 中国一级特黄真人毛片 | 久久精品国产国产 | 一级黄色美女视频 | 婷婷亚洲久悠悠色在线播放 | 亚洲看片网| 国产综合第一页 | 一级黄片一级毛片 | 欧洲一级毛片 | 亚洲成人精品 | 欧美一区二区三区日韩免费播 | 男女免费观看视频 | 日本一区二区三区欧美在线观看 | 91人人视频国产香蕉 | 成人性免费视频 | 国产或人精品日本亚洲77美色 | 亚洲精品美女 | 黄色日韩网站 | 精品国产三级a∨在线观看 精品国产三级a在线观看 | 国内免费自拍视频 | 免费观看日本高清a毛片 | 日韩特级毛片免费观看视频 | 热re91久久精品国产91热 | 日韩成人免费在线视频 | 国产91网| 手机国产日韩高清免费看片 | 国产看午夜精品理论片 | 国产一区亚洲二区 | 萌白酱粉嫩jk福利在线观看 | 日产乱码精品一二三区 | 成人久久18免费软件 | 99久久国产综合精品网成人影院 | 99精品视频在线观看re | 国产精品日产三级在线观看 |