vue.js的基本框架搭建以及菜单栏的切换

基本UI框架

<template>
    <a-layout style="height: 100%;overflow: hidden;">
        <a-layout-header style="background-color: #021629;" a-layout>
          
        </a-layout-header>
        <a-layout>
            <a-layout-sider>
                
            </a-layout-sider>
            <a-layout-content>
                
            </a-layout-content>
        </a-layout>
    </a-layout>
</template>
<script setup>

</script>
<style>

</style>

大致效果

创建一个vue.js项目

基本架构

<template>
    <a-menu></a-menu>
</template>
<script setup>

</script>
<style></style>

添加a-menu菜单组件中的各个参数

<template>
  <!-- 菜单组件 -->
  <a-menu
    style="height: 100%"
    v-model:openKeys="openKeys"
    v-model:selectedKeys="selectedKeys"
    mode="inline"
    :items="menuItem"
    @select="selectItem"
  >
  </a-menu>
</template>

<script setup>

</script>

<style></style>

完善各个参数

<template>

    <a-menu
      style="height: 100%"
      v-model:openKeys="openKeys"
      v-model:selectedKeys="selectedKeys"
      mode="inline"
      :items="menuItem"
      @select="selectItem"
    >
    </a-menu>

</template>
<script setup>
import { ref } from "vue";
import { useRouter, useRoute } from "vue-router";


const openKeys = ref(["1"]); // 菜单展开的keys
const selectedKeys = ref(["key1"]); // 当前选中的keys
const menuItem = [
{
    key: "/home",
    label: "首页",
    title: "首页",
    
  },
 {
    key: "",
    label: "业务管理",
    title: "业务管理",
    children: [

    ],
  },
  
  {
    key: "/content",
    label: "基础配置",
    title: "基础配置",
    children: [
    { key: "/content/farm", label: "牧场管理"},
  { key: "/content/pens", label: "圈舍管理"},
  { key: "/content/data", label: "数据字典"},
    ],
  },
  {
    key: "/user",
    label: "系统管理",
    title: "系统管理",
    children: [
      { key: "/user/system", label: "人员管理" },
    ],
  },
  //自行添加其它菜单项
];
const router = useRouter(); // Vue Router 实例
const route = useRoute(); // 当前路由实例
const selectItem = ({ item, key, selectedKeys }) => {
  router.push({ path: key }); // 点击菜单项时导航到相应路径
};
</script>
<style></style>

UI框架添加配置

<template>
    <a-layout style="height: 100%;overflow: hidden;">
        <a-layout-header style="background-color: #021629;" a-layout>
          
        </a-layout-header>
        <a-layout>
            <a-layout-sider>
                <MyMenu/><!--自定义别名-->
            </a-layout-sider>
            <a-layout-content>
                <router-view></router-view><!--引入router-view-->
            </a-layout-content>
        </a-layout>
    </a-layout>
</template>
<script setup>

import MyMenu from '../menu/menu.vue' //根据自己的项目实施进行修改
</script>
<style>

</style>

此时效果图:

路由配置

import {
    createRouter,
    createWebHistory,
    createWebHashHistory,
  } from "vue-router";

//懒加载的方式
//具体的导入路径根据实际的项目进行修改
  const UserLogin = () => import("../page/login/userlogin.vue");


  const routerInstance = createRouter({
    history: createWebHistory(),
    routes: [
      {path:"/user",component:UserContent},
      {
        path: "/userlogin",
        component: UserLogin,
        meta: {
          title: "用户登录",
        },
      },
      
      {
        path: "/",
        component: HomePage,
        children: [
          {
            path: "home",
            component:Home,
            name:"userlogin"
          },
          {
            path: "user",
            children: [
              {
                path: "system",
                meta: { title: "人员管理" },
                component: UserContent,
              },
            ],
          },
          {
            path: "content",
            children: [
              {
                path: "farm",
                meta: { title: "牧场管理" },
                name:"ranch",
                component: Farm,
              },
              {
                path: "pens",
                meta: { title: "圈舍管理" },
                component: Pens,
              },
              {
                path: "data",
                meta: { title: "数据字典" },
                component: DataDictionary,
              },
            ],
          },
        ],
      },
    ],
  });
  

  
  export default routerInstance;

 注意:具体的需自己配置,菜单的内容根据实际情况实现即可!

大致效果

以下是启动我的前后端项目的情况(简版):

 

 

 

 

环境配置 Node 下载地址http://nodejs.cn/ 安装文件下有一个绿色的图片交node.exe 点击运行 输入node -v进行检测是否安装成功 使用vue-cli(脚手架)搭建项目 vue-cli是vue官方提供的用域搭建基于vue+webpack_es6项目的脚手架工具 在线文档:https://github.com/vuejs/vue-cli 操作: 1.npm install -g vue-cli:全局下载工具 2.vue init webpack 项目名:下载基于webpack模板项目 3.cd 项目名:进入项目目录 4.npm install :下载项目依赖的所有模块 5.npm run dev :运行项目 6.访问项目:localhost:8080 项目目录结构 src assets:存放照片、css、js css js img components:存放组件 lib:存放模拟数据 router:配置路由 store:存放vuex vuex的安装:cd x项目目录 cnpm install vuex --save views:存放所有单页面 配置访问端口号: 根目录下有一个config文件夹,看名字就知道与配置有关,打开config目录下的index.js dev: { env: require('./dev.env'), port: 8092, autoOpenBrowser: true, assetsSubDirectory: 'static', assetsPublicPath: '/', proxyTable: {}, } 项目目录下:https://blog.csdn.net/weixin_39378691/article/details/83784403 1.安装elementUI:cd进入项目根目录,npm i element-ui -S 2.引入elementUI组件(main.js文件中) import Element from 'element-ui' import 'element-ui/lib/theme-chalk/index.css' Vue.use(Element, { size: 'small' }) 项目目录下:https://blog.csdn.net/weixin_41432849/article/details/81988058 1.安装jquery:cd进入项目根目录, npm install jquery --save 2.在项目 build 里的webpack.base.conf.js 里加载webpack文件,注意,要放在配置文件第一行; const webpack = require('webpack') 3.在module.exports的最后加入 , plugins:[ new webpack.ProvidePlugin({ $:"jquery", jQuery:"jquery", jquery:"jquery", "window.jQuery":"jquery" }) ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值