39.(前端)欢迎页面的设置

1.创建子组件

1.1概括

在我们登录完,访问home界面时,中间的Main是没实现效果的。我们可以通过给Home挂载一个Wellcome界面。当我们进入时,让其跳转到wellcome界面中。此时,相当于把home作为一个背景,中间添加占位符,把wellocome放入其中即可。

2.代码展示

2.1创建子组件

<!-- src/components/Wellcome.vue -->
<template>
    <h1>Wellcome</h1>
</template>

2.2创建子路由

// src/router/index.js
import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../components/Login.vue'
import Welcome from '../components/Welcome.vue'
import Home from '../components/Home.vue'
// 引入全局样式
import '../assets/css/global.css'


Vue.use(VueRouter)

const routes = [
  // 为login组件创建路由
  {
    path: '/login',
    name: 'Login',
    component: Login
  },
  {
    path: '/home',
    name: 'Home',
    component: Home,
    // 引入子组件,创建子路由
    redirect: '/welcome',
    children: [
      {
        path: '/welcome', component: Welcome
      }
    ]
  }
]
const router = new VueRouter({
  routes
})

export default router



// 根据用户当前是否登录,在访问之前做一个判断
router.beforeEach ((to, from, next) => {
  if (to.path == '/login') return next() // 如果直接访问login界面,那就跳转过去
  // 如果不是直接访问登录界面,看一下他有没有token,如果没有的话,先让他登录,有就想去哪去哪
  const tokenStr = window.sessionStorage.getItem('token')
  if (!tokenStr) return next('/login')
  next()
})

2.3占位

<!-- src/compoents/Home.vue -->
<template>
    <el-container class="home-container">
        <el-header>
            <div>
                <img src="../assets/logo.png">
                <span>电子后台管理系统</span>
            </div>
            <el-button type="primary" @click="logout">退出</el-button>
        </el-header>
        <el-container>
            <el-aside width="200px">
        <el-menu default-active="2" class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose"
        background-color="#303133" text-color="#fff" active-text-color="#409EFF" unique-opened>
        <!-- 遍历传递数据给导航 -->
        <!-- 给index加冒号意思是:使他变成一个变量 -->
        <el-submenu :index="item.id+''" v-for=" item in menuList" :key="item.id">
            <template slot="title">
                <i :class="IconObj[item.id+'']"></i>
                <span>{{item.name}}</span>
            </template>
            <el-menu-item :index="subItem.id+''" v-for="subItem in item.children" :key="subItem.id">
                <i :class="IconObj[subItem.id+'']"></i>
                    <span>{{subItem.name}}</span>
                    </el-menu-item>
            </el-submenu>
        </el-menu>
            </el-aside>
            <el-main>
                <router-view></router-view>
            </el-main>
    </el-container>
    </el-container>
</template>

<script>
import { Icon } from 'element-ui';

export default{
    // 存储导航数据
    data () {
        return {
            menuList: [],
            IconObj:{
                '1':'el-icon-user-solid',
                '2':'el-icon-s-tools',
                '3':'el-icon-s-shop',
                '4':'el-icon-s-order',
                '5':'el-icon-s-tools',
                '11':'el-icon-user',
                '21':'el-icon-setting',
                '22':'el-icon-setting',
                '31':'el-icon-goods',
                '32':'el-icon-goods',
                '33':'el-icon-goods'

            }
        }
    },
    // 创建时被执行的函数
    created () {
        this.getMenulist()
        console.log(this.menuList);
    },
    methods:{
        logout (){
            // 第一步,清除token
            window.sessionStorage.clear()
            // 第二步,跳转到登录页面
            this.$router.push('/login')
        },
        handleOpen(key, keyPath) {
            console.log(key, keyPath);
        },
        handleClose(key, keyPath) {
            console.log(key, keyPath);
        },
        // 从后端中获取数据
        // 由于我们想在他刷新页面时候就能够显示出来,所以得改为同步操作;不改的话就可能会找不到
        async getMenulist () {
            const {data: res} = await this.$axios.get('/api/menu')
            // console.log(res.data);
            this.menuList = res.data
            // console.log(res.data);
        }
    }
}
</script>

<style lang="less" scoped>
// 整个组件

.home-container{
    height: 100%;
}
// 界面顶
.el-header{
    display: flex;
    align-items: center; //居中操作
    background-color: #409EFF;
    justify-content: space-between;
    color: #fff;
    font-size: 20px;
    img{
        height: 50px;
        width: 100px;
    }
    div{
        display: flex;
        align-items: center;
    }
}
// 侧面
.el-aside{
    background-color: #303133;
}
// 中间
.el-main{
    background-color: #e4e7ed;
}
</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
jquery.i18n.properties是一个轻量级的jQuery国际化插件,用于在前端页面实现资源国际化。下面是一个基于jquery.i18n.properties实现前端页面的资源国际化的示例代码: 1. 引入依赖: ```html <script src="jquery.min.js"></script> <script src="jquery.i18n.properties.min.js"></script> ``` 2. 创建资源文件: 在项目的根目录下创建针对每种语言的资源文件,例如 `messages.properties`、`messages_zh.properties`、`messages_en.properties`,分别用于存储不同语言的资源信息。 messages.properties: ``` welcome_title=欢迎使用 welcome_message=你好,世界! ``` messages_zh.properties: ``` welcome_title=歡迎使用 welcome_message=你好,世界! ``` messages_en.properties: ``` welcome_title=Welcome welcome_message=Hello, world! ``` 3. 初始化插件: ```javascript $(function() { jQuery.i18n.properties({ name: &#39;messages&#39;, path: &#39;path/to/resources/&#39;, mode: &#39;both&#39;, language: &#39;zh&#39;, callback: function() { // 执行其他需要进行国际化的逻辑 $(&#39;#title&#39;).text($.i18n.prop(&#39;welcome_title&#39;)); $(&#39;#message&#39;).text($.i18n.prop(&#39;welcome_message&#39;)); } }); }); ``` 通过调用jQuery.i18n.properties来初始化该插件,其中name参数指定了资源文件的前缀名,path参数指定了资源文件的路径,mode参数设置为&#39;both&#39;以支持服务器端和客户端的资源文件加载方式,并通过language参数指定了应加载的语言版本。在回调函数中,可以通过$.i18n.prop方法获取指定资源的国际化文本。 4. 在HTML中使用国际化资源: ```html <h1 id="title"></h1> <p id="message"></p> ``` 以上代码将根据不同的语言版本显示不同的欢迎标题和消息。 通过上述步骤,可以实现前端页面的资源国际化,根据不同的语言版本加载对应的资源文件,并将资源中定义的文本进行国际化显示。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

想成为数据分析师的开发工程师

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

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

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

打赏作者

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

抵扣说明:

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

余额充值