vue后台管理项目中菜单栏切换的三种方法

第一种方法:vue嵌套路由(二)

<el-menu :default-active="defaultActive" style="min-height: 100%;" theme="dark" router>
                        <el-menu-item index="manage">
                            <i class="el-icon-menu"></i>首页
                        </el-menu-item>
                        <el-submenu index='2'>
                            <template slot='title'>
                                <i class="el-icon-document"></i>用户管理
                            </template>
                            <el-menu-item index="userList">用户查询</el-menu-item>
                            <el-menu-item index="userforbid">封号管理</el-menu-item>
                            <el-menu-item index="userapply">用户申请</el-menu-item>
                        </el-submenu>
                    </el-menu>

<el-col :span="20" style="min-height:100%;background:#F2F4F8">
  <router-view></router-view>
</el-col>

在js中

{
        path:'/manage',
        component: manage,
        name:'',
        children:[{
            path:'/userList',
            component:userList,
            meta: ['用户列表']
        }]
    }

当我们点击用户查询时,就会跳转到http://localhost:8080/#/userList

 

第二种方法点击事件

<el-button :plain="true" type="success" @click="goadd">    



  goadd(){
              this.$router.push({ path: '/addcategory' })
          }

 

第三种方法命名路由:

<div id="app">  
    <h1>Named Routes</h1>  
    <p>Current route name: {{ $route.name }}</p>  
    <ul>  
        <li><router-link :to="{ name: 'home' }">home</router-link></li>  
        <li><router-link :to="{ name: 'foo' }">foo</router-link></li>  
        <li><router-link :to="{ name: 'bar', params: { id: 123 }}">bar</router-link></li>  
    </ul>  
    <router-view class="view"></router-view>  
</div>  
  
<template id='home'>  
    <div>This is Home</div>  
</template>  
  
<template id='foo'>  
    <div>This is Foo</div>  
</template>  
  
<template id='bar'>  
    <div>This is Bar {{ $route.params.id }}</div>  
</template>  





const Home = { template: '#home' };  
const Foo = { template: '#foo' };  
const Bar = { template: '#bar' };  
  
const router = new VueRouter({  
    routes: [  
        { path: '/', name: 'home', component: Home },  
        { path: '/foo', name: 'foo', component: Foo },  
        { path: '/bar/:id', name: 'bar', component: Bar }  
    ]  
});  
  
new Vue({ router:router }).$mount('#app');  

第四种方法命名视图:

<div id="app">  
    <router-link to="/">Go to Foo</router-link>  
    <router-view class="view one"></router-view>  
    <router-view class="view two" name="a"></router-view>  
    <router-view class="view three" name="b"></router-view>  
</div>  
  
<template id='foo'>  
    <div>This is Foo</div>  
</template>  
  
<template id='bar'>  
    <div>This is Bar {{ $route.params.id }}</div>  
</template>  
  
<template id='baz'>  
    <div>This is baz</div>  
</template>  


const Foo = { template: '#foo' };  
const Bar = { template: '#bar' };  
const Baz = { template: '#baz' };  
  
const router = new VueRouter({  
    routes: [  
        {  
            path: '/',  
            components: {  
                default:Foo,  
                a:Bar,  
                b:Baz  
            }  
        }  
    ]  
});  
  
new Vue({ router:router }).$mount('#app');  

第五种方法

<div id="app">  
    <h1>Hello App!</h1>  
    <p>  
        <!-- 使用 router-link 组件来导航. -->  
        <!-- 通过传入 `to` 属性指定链接. -->  
        <!-- <router-link> 默认会被渲染成一个 `<a>` 标签 -->  
        <router-link to="/foo">Go to Foo</router-link>  
        <router-link to="/bar">Go to Bar</router-link>  
    </p>  
    <!-- 路由出口 -->  
    <!-- 路由匹配到的组件将渲染在这里 -->  
    <router-view></router-view>  
</div>  
  
<template id='foo'>  
    <p>this is foo!</p>  
</template>  
<template id='bar'>  
    <p>this is bar!</p>  
</template>  


// 1. 定义(路由)组件。  
// 可以从其他文件 import 进来  
const Foo = { template:'#foo' };  
const Bar = { template:'#bar' };  
// 2. 定义路由  
// 每个路由应该映射一个组件。 其中"component" 可以是  
// 通过 Vue.extend() 创建的组件构造器,  
// 或者,只是一个组件配置对象。  
const routes = [  
    { path: '/foo', component: Foo },  
    { path: '/bar', component: Bar }  
];  
// 3. 创建 router 实例,然后传 `routes` 配置  
// 你还可以传别的配置参数, 不过先这么简单着吧。  
const router = new VueRouter({ routes:routes });  
// 4. 创建和挂载根实例。  
// 记得要通过 router 配置参数注入路由,  
// 从而让整个应用都有路由功能  
const app = new Vue({ router:router }).$mount('#app');  

引:http://blog.csdn.net/bboyjoe/article/details/52804988

转载于:https://www.cnblogs.com/myzy/p/7112368.html

Vue2后台系统,左菜单栏的折叠展开功能是指左侧导航菜单的可折叠和展开状态。这个功能通常用来优化界面显示,当导航菜单过长时,可以将其折叠起来,以节省页面空间,增强用户体验。 实现左菜单栏的折叠展开功能可以考虑以下步骤: 1. 在Vue组件定义一个变量menuCollapsed来标记左菜单栏的折叠与展开状态,默认为false。 2. 在菜单栏的最外层div元素上绑定一个class,通过类名来控制菜单栏的宽度和显示方式。通过:class绑定判断menuCollapsed的值,来添加折叠和展开时的样式类。 3. 在菜单的折叠展开按钮上绑定一个点击事件,点击时改变menuCollapsed的值,实现菜单栏的折叠与展开。 4. 在菜单项的列表上根据menuCollapsed的值来决定是否显示菜单项的文字。 具体代码如下: ```html <template> <div class="menu-container" :class="{'collapsed': menuCollapsed}"> <button class="collapse-button" @click="toggleMenu"> {{ menuCollapsed ? '展开' : '折叠' }} </button> <ul class="menu-items"> <li v-for="item in menuItems" :key="item.id" :class="{'hidden-text': menuCollapsed}"> {{ item.title }} </li> </ul> </div> </template> <script> export default { data() { return { menuCollapsed: false, menuItems: [ { id: 1, title: '菜单项1' }, { id: 2, title: '菜单项2' }, { id: 3, title: '菜单项3' } ] } }, methods: { toggleMenu() { this.menuCollapsed = !this.menuCollapsed; } } } </script> <style> .menu-container { width: 200px; transition: width 0.3s; } .collapsed { width: 50px; } .collapse-button { margin-bottom: 10px; width: 100%; text-align: center; } .hidden-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } </style> ``` 以上代码实现了一个简单的左菜单栏的折叠展开功能。通过点击```.collapse-button```按钮,可以切换菜单栏的折叠与展开状态。菜单项目在折叠状态下会隐藏文字,并且用省略号表示。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值