vue中的菜单切换menu

项目需要点击按钮进入一个可以进行菜单切换的页面。

效果如图:

1.写左边的菜单栏

<Col :span="2">
  <Menu  active-name="rwcl" style="width:auto;" @on-select="changeMenu">
    <MenuItem name="rwcl">
      任务处理
    </MenuItem>
    <MenuItem name="lct">
      流程图
    </MenuItem>
  </Menu>
</Col>

2.写右边的两个页面(任务处理和流程图)

<Col :span="22">
  <!-- 任务处理 -->
  <div style="height:100%" v-if="this.activeName === 'rwcl'">
    <Form ref="rwcl
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
要实现菜单页面切换,可以使用Vue.jsElement UIel-menu组件。 1. 首先,在Vue.js定义一个数据对象,用来存储菜单选项和对应的页面路由: ``` data() { return { menuItems: [ { index: 'home', title: '首页', route: '/' }, { index: 'about', title: '关于我们', route: '/about' }, { index: 'contact', title: '联系我们', route: '/contact' } ] } } ``` 2. 在模板,使用el-menu组件来渲染菜单。设置mode属性为horizontal,表示菜单水平排列;设置default-active属性为当前选菜单项的index值: ``` <el-menu :default-active="$route.path" mode="horizontal"> <el-menu-item v-for="item in menuItems" :key="item.index" :index="item.route">{{ item.title }}</el-menu-item> </el-menu> ``` 3. 在路由配置,定义对应的页面组件,并设置路由路径为菜单项的route值: ``` const routes = [ { path: '/', component: Home }, { path: '/about', component: About }, { path: '/contact', component: Contact } ] ``` 4. 最后,在页面组件,使用Vue.js的路由功能来实现页面切换。例如,在点击菜单项时,使用this.$router.push()方法将路由切换到对应的页面: ``` methods: { handleMenuSelect(index) { this.$router.push(index) } } ``` 完整代码示例: ``` <template> <el-menu :default-active="$route.path" mode="horizontal" @select="handleMenuSelect"> <el-menu-item v-for="item in menuItems" :key="item.index" :index="item.route">{{ item.title }}</el-menu-item> </el-menu> </template> <script> import Home from './Home.vue' import About from './About.vue' import Contact from './Contact.vue' export default { data() { return { menuItems: [ { index: 'home', title: '首页', route: '/' }, { index: 'about', title: '关于我们', route: '/about' }, { index: 'contact', title: '联系我们', route: '/contact' } ] } }, methods: { handleMenuSelect(index) { this.$router.push(index) } }, components: { Home, About, Contact } } </script> <style scoped> /* 样式 */ </style> ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

芝士焗红薯

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值