在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
目的: 实现功能:制作一个登录页面,跳转到首页,首页包含菜单栏、顶部导航栏、主体,标准的后台网页格式。菜单栏点击不同菜单控制主体展示不同的组件(不同的页面)。 配置 我这里使用的是element-ui作为模板 前置:引入 在项目目录下执行命令: 修改 步骤:
1、修改app.vue页面app页面只要放置一个 <template> <div id="app"> <router-view></router-view> </div> </template> <script> export default { name: 'App', methods: { } } </script> <style> </style> 2、创建登录页面(/views/login/login.vue)这里的登录按钮跳转是直接跳转到主页面,当前登陆页面将完全被替换掉 登录页代码 <template> <div id="login"> <el-form> <el-row :gutter="20"> <el-col class="title" :offset="9" :span="6"> <h1>一个登录页面</h1> </el-col> </el-row> <el-row :gutter="20"> <el-col class="col-label" :offset="7" :span="4"> <span class="label">账号:</span> </el-col> <el-col :span="4"> <el-input type="text" placeholder="请输入账号" v-model="account.username"></el-input> </el-col> </el-row> <el-row :gutter="20"> <el-col class="col-label" :offset="7" :span="4"> <span class="label">密码:</span> </el-col> <el-col :span="4"> <el-input type="password" placeholder="请输入密码" v-model="account.password"></el-input> </el-col> </el-row> <el-row :gutter="20"> <el-col :offset="8" :span="8"> <span> <a href="#" rel="external nofollow" rel="external nofollow" @click="register" >注册账号</a> / <a href="#" rel="external nofollow" rel="external nofollow" @click="resetPwd" >重置密码</a> </span> </el-col> </el-row> <el-row :gutter="20"> <el-col :offset="10" :span="4"> <el-button type="primary" round @click="onSubmit">登录</el-button> </el-col> </el-row> </el-form> </div> </template> <script> export default { name: 'login', data() { return { account: { username: '', password: '' } } }, methods: { register() { this.$message({ message: '好像没这功能', type: 'info' }) }, resetPwd() { this.$message({ message: '下辈子吧', type: 'success' }) }, onSubmit() { this.$router.push('/index') } } } </script> <style scoped> #login { text-align: center; margin: 0 auto; } .label { height: 40px; line-height: 40px; } .col-label { text-align: right; } .el-row { margin-top: 15px; } .el-button { width: 120px; } .title { margin-top: 10%; } </style> View Code 2.1、在router/index.js中添加登录页面路由{ path: '/', name: 'login', component: () => import('../views/login/login.vue') }, 3、创建主页面(/components/index.vue)主页面主要分为三块, <template> <el-container style="border: 1px solid #eee"> <el-aside width="200px" style="background-color: rgb(238, 241, 246)"> <el-menu :default-openeds="['1']" :router="true"> <el-submenu index="1"> <template slot="title"><i class="el-icon-message"></i>导航一</template> <el-menu-item-group> <template slot="title">分组一</template> <el-menu-item index="1-1">选项1</el-menu-item> <el-menu-item index="1-2">选项2</el-menu-item> </el-menu-item-group> </el-submenu> </el-menu> </el-aside> <el-container class="table-div"> <el-header style="text-align: right; font-size: 12px"> <el-dropdown> <i class="el-icon-setting" style="margin-right: 15px"></i> <el-dropdown-menu slot="dropdown"> <el-dropdown-item>查看</el-dropdown-item> <el-dropdown-item>新增</el-dropdown-item> <el-dropdown-item>删除</el-dropdown-item> </el-dropdown-menu> </el-dropdown> <span>王小虎</span> </el-header> <el-main> <table></table> </el-main> </el-container> </el-container> </template> <style> .el-header { background-color: #B3C0D1; color: #333; line-height: 60px; } .el-aside { color: #333; } </style> <script> export default { name: 'index', data() { } } </script> <style> .table-div { width: 100%; } .el-table { height: 100%; } </style> 3.1、创建主页面路由{ path: '/index', name: 'index', component: () => import('@/components/index') } 至此,由登录页面跳转到主页面的操作配置就完成了。看看效果。启动项目,访问http://localhost:8080/#/ 点击登录,跳转到首页 4、修改首页主要修改两个部分:菜单跳转路径,主体配置路由视图 4.1、开启菜单路由模式,并修改菜单跳转路径
|
请发表评论