【移动端】动态实现主页点击图标跳转

这篇博客展示了如何使用Vue.js和Van组件库来构建一个智能产品系统的导航主页面。主要内容包括设置导航栏,响应式布局,以及通过点击事件处理路由跳转。示例代码详细解释了如何动态渲染菜单图标并链接到不同的子页面。此外,还包含了菜单数据结构的定义,使得添加新模块变得简单。
摘要由CSDN通过智能技术生成

在这里插入图片描述

<!-- 导航主页面-->
<template>
    <div id="home">
        <van-nav-bar title="智能产品系统" class="header"  @click-right="onClickRight">
            <template #right>
                <img src="@/assets/images/ic_toolbar_user.png">
            </template>
        </van-nav-bar>
        <div class="menu-flex">
            <div v-for="item in MENUDATE" @click="handleClick(item)" class="menu-img">
                <!-- 按class名动态渲染,图标做背景-->
                <div :class="[item.icon]"></div>
                <p>{{ item.name }}</p>
            </div>
        </div>
    </div>
</template>

<script>
import{ MENU }from '../../../router/menu'

export default {
    name: "home",
    data() {
        return {
            MENUDATE:MENU
        }
    },
    methods: {
        handleClick(e) {
            console.log(e)
            this.$router.push({
                path : e.path,
                query: {
                    params: JSON.stringify(e)
                }
            })
        },
        onClickRight(){  // 跳转个人中心页面
            this.$router.push({ path: '/setting'})
        }
    }
}
</script>

<style lang="less">
    #home{
        p {
            font-size: 16px;
        }
        .header{
            background-image: linear-gradient(to right bottom, rgb(36, 61, 142) 0%, rgb(69, 92, 163) 100%);
            .van-nav-bar__title {
                color: #eee;
                font-size: 22px;
            }
        }
        .menu-flex{
            display: flex;
            flex-direction: row;
            flex-wrap: wrap;
            .menu-img {
                width: 33%;
                height: 130px;
                margin-top: 30px;
                display: flex;
                flex-direction: column; /* 控制文字在下方*/
                align-items: center;
                background-position: center;
                background-repeat: no-repeat;
                div{

                    width: 100px;
                    height: 100px;
                }
                .task-move-agv {
                    background: url("../../../assets/images/ic_task_move_agv.png");
                    background-size: cover;
                }
                .task-new-task {
                    background: url("../../../assets/images/ic_task_new_task.png");
                }
            }
        }
    }
</style>

menu.js示例

/**
 * 目录菜单
 * 这样写好处是增加模块时只需要增加一项数组对象
 */


export const MENU = [
    {
        name: '作业',
        path: '/agv',
        icon: 'task-move-agv',
        child: [
            {
                name: '绑定与解绑',
                path: '/agv/dealPodAndBerth',
                icon: 'init-bound',
            },
            {
                name: '初始化',
                path: '/agv/initPod',
                icon: 'out-bound'
            },
            {
                name: '循环',
                path: '/agv/CycleOut',
                icon: 'physical-count'
            },
            {
                name: '叫料',
                path: '/agv/MaterialOutbound',
                icon: 'physical-count'
            },
        ]
    },
    {
        name: '人工',
        path: '/artificial',
        icon: 'task-new-task',
        child: [
            {
                name: '上架',
                path: '/artificial/Puton',
                icon: 'init-bound'
            },
            {
                name: '理货',
                path: '/artificial/ArtificialTally',
                icon: 'physical-count'
            },
            {
                name: '盘点',
                path: '/artificial/',
                icon: 'physical-count'
            }
        ]
    }
]

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值