• vue2设置首页和个人信息页


    vue2设置首页和个人信息页

    设置首页

    编辑client/src/views/Home.vue

    <template>
        <div class="home">
            <div class="container">
                <h1 class="title">MamaHuhu资金管理系统</h1>
                <p class="lead">千里之堤,溃于蚁穴。细节决定成败!</p>
            </div>
        </div>
    </template>
    
    <style scoped>
        .home {
            width: 100%;
            height: 100%;
            background: url(../assets/showcase.png) no-repeat;
            background-size: 100% 100%;
        }
    
        .container {
            width: 100%;
            height: 100%;
            box-sizing: border-box;
            padding-top: 100px;
            background-color: rgba(0, 0, 0, 0.7);
            text-align: center;
            color: white;
        }
    
        .title {
            font-size: 30px;
        }
    
        .lead {
            margin-top: 50px;
            font-size: 22px;
        }
    </style>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36

    编辑client/src/views/Index.vue,添加router-view以显示Home组件:

    <template>
        <div class="index">
            <HeadNav></HeadNav>
            <router-view></router-view>
        </div>
    </template>
    
    <script>
        import HeadNav from "../components/HeadNav"
        export default {
          name: 'index',
          components: {
            HeadNav
          }
        };
    </script>
    
    <style>
        .index {
            width: 100%;
            height: 100%;
            overflow: hidden;
        }
    
    </style>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25

    编辑client/src/router/index.js,为Home配置路由:

    import Vue from 'vue'
    import VueRouter from 'vue-router'
    import Index from '../views/Index.vue'
    import Register from '../views/Register.vue'
    import Login from '../views/Login.vue'
    import NotFound from '../views/404.vue'
    import Home from '../views/Home.vue'
    
    Vue.use(VueRouter)
    
    const routes = [
      {
        path: '/',
        redirect: 'index'
      },
      {
        path: '/index',
        name: 'index',
        component: Index,
          children: [
              { path: '', component: Home },
              { path: '/home', name: 'home', component: Home }
          ]
       },
      {
          path: '/register',
          name: 'register',
          component: Register
        },
      {
            path: '/login',
            name: 'login',
            component: Login
        },
      {
          path: '*',
          name: '/404',
          component: NotFound
      }
    ]
    
    const router = new VueRouter({
      mode: 'history',
      base: process.env.BASE_URL,
      routes
    })
    
    router.beforeEach((to, from, next) => {
        const isLogin = localStorage.eleToken ? true : false;
        if (to.path == '/login' || to.path == '/register') {
            next();
        } else {
            isLogin ? next() : next('/login');
        }
    });
    
    export default router
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57

    设置个人信息页

    编辑client/src/router/index.js,为个人信息页面配置路由:

    import Vue from 'vue'
    import VueRouter from 'vue-router'
    import Index from '../views/Index.vue'
    import Register from '../views/Register.vue'
    import Login from '../views/Login.vue'
    import NotFound from '../views/404.vue'
    import Home from '../views/Home.vue'
    import InfoShow from '../views/InfoShow'
    
    Vue.use(VueRouter)
    
    const routes = [
      {
        path: '/',
        redirect: 'index'
      },
      {
        path: '/index',
        name: 'index',
        component: Index,
          children: [
              { path: '', component: Home },
              { path: '/home', name: 'home', component: Home },
              { path: '/infoshow', name: 'infoshow', component: InfoShow }
          ]
       },
      {
          path: '/register',
          name: 'register',
          component: Register
        },
      {
            path: '/login',
            name: 'login',
            component: Login
        },
      {
          path: '*',
          name: '/404',
          component: NotFound
      }
    ]
    
    const router = new VueRouter({
      mode: 'history',
      base: process.env.BASE_URL,
      routes
    })
    
    router.beforeEach((to, from, next) => {
        const isLogin = localStorage.eleToken ? true : false;
        if (to.path == '/login' || to.path == '/register') {
            next();
        } else {
            isLogin ? next() : next('/login');
        }
    });
    
    export default router
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59

    创建个人信息展示页面InfoShow.vue

    <template>
        <div class="infoshow">
            <el-row type="flex" class="row-bg" justify="center">
                <el-col :span="8">
                    <div class="user">
                        <img :src="user.avatar" class="avatar" alt="" />
                    </div>
                </el-col>
                <el-col :span="16">
                    <div class="userinfo">
                        <div class="user-item">
                            <i class="fa fa-user"></i>
                            <span>{{user.name}}</span>
                        </div>
                        <div class="user-item">
                            <i class="fa fa-cog"></i>
                            <span>{{user.identity == "manager" ? "经理":"员工"}}</span>
                        </div>
                    </div>
                </el-col>
            </el-row>
        </div>
    </template>
    
    <script>
        export default {
            name: 'infoshow',
            computed: {
                user() {
                    return this.$store.getters.user;
                }
            }
        }
    
    </script>
    
    <style scoped>
        .infoshow {
            width: 100%;
            height: 100%;
            box-sizing: border-box;
            /* padding: 16px; */
        }
    
        .row-bg {
            width: 100%;
            height: 100%;
        }
    
        .user {
            text-align: center;
            position: relative;
            top: 30%;
        }
    
        .user img {
            width: 150px;
            border-radius: 50%;
        }
    
        .user span {
            display: block;
            text-align: center;
            margin-top: 20px;
            font-size: 20px;
            font-weight: bold;
        }
    
        .userinfo {
            height: 100%;
            background-color: #eee;
        }
    
        .user-item {
            position: relative;
            top: 30%;
            padding: 26px;
            font-size: 28px;
            color: #333;
        }
    </style>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81

    client/public/index.html中引入font-awesome.css

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width,initial-scale=1.0">
        <link rel="icon" href="<%= BASE_URL %>favicon.ico">
        <link href="//cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.css" rel="stylesheet">
        <link rel="stylesheet" href="css/reset.css">
        <title><%= htmlWebpackPlugin.options.title %></title>
    </head>
      <body>
        <noscript>
          <strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
        </noscript>
        <div id="app"></div>
        <!-- built files will be auto injected -->
      </body>
    </html>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

    编辑client/src/components/HeadNav.vue,修改下拉菜单的showInfoList方法:

    methods: {
                setDialogInfo(cmdItem) {
                    //console.log(cmdItem);
                    switch (cmdItem) {
                        case "info":
                            this.showInfoList();
                            break;
                        case "logout":
                            this.logout();
                            break;
                    }
                },
                showInfoList() {
                    this.$router.push('/infoshow');
                },
                logout() {
                    //清除token
                    localStorage.removeItem('eleToken');
                    //设置Vuex store
                    this.$store.dispatch('clearCurrentState');
                    //跳转到登录页面
                    this.$router.push('/login');
                }
            }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
  • 相关阅读:
    网络安全-漏洞与木马
    EthernetIP 转MODBUS RTU协议网关连接FANUC机器人作为EthernetIP通信从站
    适合女生佩戴的蓝牙耳机有什么推荐?五款高性价比蓝牙耳机
    推荐一款专用低代码工具,一天开发一个系统不是梦
    嵌入式物联网实战开发笔记-乐鑫ESP32开发环境ESP-IDF搭建【doc.yotill.com】
    MySQL表的内外连接
    Codeforces Round #833 (Div. 2) D. ConstructOR(构造 逆元/exgcd)
    智慧城市-疫情流调系列4-GlobalPointer
    DPU — 功能特性 — 存储系统的硬件卸载
    OMV6 安装Extras 插件失败的解决方法
  • 原文地址:https://blog.csdn.net/Sebastien23/article/details/125548440