电脑知识|欧美黑人一区二区三区|软件|欧美黑人一级爽快片淫片高清|系统|欧美黑人狂野猛交老妇|数据库|服务器|编程开发|网络运营|知识问答|技术教程文章 - 好吧啦网

您的位置:首頁技術文章
文章詳情頁

Vue實現登陸跳轉

瀏覽:49日期:2022-09-28 10:30:13

本文實例為大家分享了Vue實現登陸跳轉的具體代碼,供大家參考,具體內容如下

不說廢話,先上效果圖~

Vue實現登陸跳轉

Vue實現登陸跳轉

Vue實現登陸跳轉

Vue實現登陸跳轉

Vue實現登陸跳轉

具體的實現方法,參照以下步驟~

1.創建login.vue,繪制login畫面,添加跳轉事件。

<template> <div class='login-container'><el-form :model='ruleForm2' :rules='rules2' status-icon ref='ruleForm2' label-position='left' label- class='demo-ruleForm login-page'> <h3 class='title'>登錄平臺</h3> <el-form-item prop='username'><el-input type='text' v-model='ruleForm2.username' auto-complete='off' placeholder='用戶名'></el-input> </el-form-item> <el-form-item prop='password'><el-input type='password' v-model='ruleForm2.password' auto-complete='off' placeholder='密碼'></el-input> </el-form-item> <el-form-item style='width:100%;'><el-button type='primary' @click='handleSubmit' :loading='logining'>登錄</el-button> </el-form-item> <el-form-item ><el-checkbox v-model='checked' class='rememberme'>記住密碼</el-checkbox><el-button type='text' @click='forgetpassword'>忘記密碼</el-button> </el-form-item> </el-form> </div></template><script> import { requestLogin } from ’../api/api’; export default { data() { return {logining: false,ruleForm2: {},rules2: { account: [ { required: true, message: ’請輸入賬號’, trigger: ’blur’ }, ], checkPass: [ { required: true, message: ’請輸入密碼’, trigger: ’blur’ }, ]},checked: true }; }, methods: { handleReset2() {this.$refs.ruleForm2.resetFields(); }, handleSubmit(ev) {this.$refs.ruleForm2.validate((valid) => { if (valid) { this.logining = true; var loginParams = { username: this.ruleForm2.username, password: this.ruleForm2.password, identifycode: this.ruleForm2.identifycode }; requestLogin(loginParams).then(data => { this.logining = false; let { msg, code, user } = data; if (code !== 200) {this.$message({ message: msg, type: ’error’}); } else {if (user.type === 'admin'){ sessionStorage.setItem(’user’, JSON.stringify(user)); this.$router.push({ path: ’/homepage’ });} else if (user.type === 'advert') { sessionStorage.setItem(’user’, JSON.stringify(user)); this.$router.push({ path: ’/table’ });} } }); } else { console.log(’error submit!!’); return false; }}); }, forgetpassword(){ this.$alert(’請聯系管理員找回密碼,管理員電話:131xxxxxxxx’, ’提示’, { confirmButtonText: ’確定’, type: ’warning’}) } } }</script><style scoped> label.el-checkbox.rememberme {margin: 0px 0px 15px;text-align: left; } label.el-button.forget {margin: 0;padding: 0;border: 1px solid transparent;outline: none; }</style>

2.創建Home.vue菜單欄頁面

<template> <el-row class='container'><el-col :span='24' class='header'> <el-col :span='18' >{{sysName}} </el-col> <el-col :span='4' class='userinfo'> <el-dropdown trigger='hover'> <span class='el-dropdown-link userinfo-inner'><img :src='http://www.hdgsjgj.cn/bcjs/this.sysUserAvatar' /> {{sysUserName}}</span> <el-dropdown-menu slot='dropdown'> <el-dropdown-item>我的消息</el-dropdown-item> <el-dropdown-item>設置</el-dropdown-item> <el-dropdown-item @click.native='logout'>退出登錄</el-dropdown-item> </el-dropdown-menu> </el-dropdown> </el-col> </el-col><el-col :span='24' class='main'> <aside><el-menu :default-active='$route.path' @select='handleselect'unique-opened router ><template v-for='(item,index) in $router.options.routes' v-if='!item.hidden'> <el-submenu :index='index+’’' v-if='!item.leaf'> <template slot='title'><i :class='item.iconCls'></i>{{item.name}}</template> <el-menu-item v-for='child in item.children' :index='child.path' :key='child.path' v-if='!child.hidden'>{{child.name}}</el-menu-item> </el-submenu> <el-menu-item v-if='item.leaf&&item.children.length>0' :index='item.children[0].path'><i :class='item.iconCls'></i>{{item.children[0].name}}</el-menu-item> </template></el-menu> </aside> <section class='content-container'> <div class='grid-content bg-purple-light'> <el-col :span='24' class='breadcrumb-container'> <strong class='title'>{{$route.name}}</strong> </el-col> <el-col :span='24' class='content-wrapper'> <transition name='fade' mode='out-in'> <router-view></router-view> </transition> </el-col> </div> </section> </el-col> </el-row></template><script>export default { data() { return { sysName:’xxx管理平臺’, sysUserName: ’’, sysUserAvatar: ’’, form: { name: ’’, region: ’’, date1: ’’, date2: ’’, delivery: false, type: [], resource: ’’, desc: ’’ } }}, methods: { //退出登錄 logout: function () { var _this = this; this.$confirm(’確認退出嗎?’, ’提示’, { //type: ’warning’ }).then(() => { sessionStorage.removeItem(’user’); _this.$router.push(’/login’); }).catch(() => { }); } }, mounted() { var user = sessionStorage.getItem(’user’); if (user) { user = JSON.parse(user); this.sysUserName = user.name || ’’; this.sysUserAvatar = user.avatar || ’’; } }}</script><style scoped lang='scss'>@import ’../style/vars.scss’; .container { position: absolute; top: 0px; bottom: 0px; width: 100%; } .header { height: 60px; line-height: 60px; background: $color-primary; color:#fff; .userinfo { text-align: right; padding-right: 35px; float: right; .userinfo-inner { cursor: pointer; color:#fff; img { width: 40px; height: 40px; border-radius: 20px; margin: 10px 0px 10px 10px; float: right; } } } .logo { height:60px; font-size: 22px; padding-left:20px; img { width: 40px; float: left; margin: 10px 10px 10px 0px; } .txt { color:#fff; } } .logo-width{ width:230px; } .logo-collapse-width{ width:60px } .title{font-size: 22px; padding-left:20px; line-height: 60px; color:#fff; }} .main { display: flex; position: absolute; top: 60px; bottom: 0px; overflow: hidden; aside { flex:0 0 230px; width: 230px; .el-menu{ height: 100%; /* width: 34%; */ } } .content-container { flex:1; /* overflow-y: scroll; */ padding: 20px; .breadcrumb-container { .title { width: 200px; float: left; color: #475669; } .breadcrumb-inner { float: right; } } .content-wrapper { background-color: #fff; box-sizing: border-box; } } }</style>

3.制作子頁面

<template> <p> homepage</p></template>

4.路由配置

import Login from ’./views/Login.vue’import Home from ’./views/Home.vue’import Homepage from ’./views/list/homepage.vue’ import Table from ’./views/list/Table.vue’let routes = [ {path: ’/login’,component: Login,name: ’’,hidden: true }, {path: ’/’,component: Home,name: ’’,leaf: true,//只有一個節點iconCls: ’el-icon-menu’, //圖標樣式classchildren: [ { path: ’/homepage’, component: Homepage, name: ’首頁’ },] }, {path: ’/’,component: Home,name: ’菜單’,// leaf: true,//只有一個節點iconCls: ’el-icon-message’, //圖標樣式classchildren: [ { path: ’/table’, component: Table, name: ’子菜單01’ }] }];export default routes;

5.main.js實現

// The Vue build version to load with the `import` command// (runtime-only or standalone) has been set in webpack.base.conf with an alias.import Vue from ’vue’import App from ’./App’import VueRouter from ’vue-router’import routes from ’./routes’import Vuex from ’vuex’import store from ’./vuex/store’import ElementUI from ’element-ui’import ’element-ui/lib/theme-chalk/index.css’import Mock from ’./mock’Mock.bootstrap();import ’./style/login.css’/* Vue.use(VueAxios, axios) */Vue.use(ElementUI)Vue.use(VueRouter)Vue.use(Vuex)Vue.config.productionTip = falseconst router = new VueRouter({ routes})router.beforeEach((to, from, next) => { //NProgress.start(); if (to.path == ’/login’) { sessionStorage.removeItem(’user’); } let user = JSON.parse(sessionStorage.getItem(’user’)); if (!user && to.path != ’/login’) { next({ path: ’/login’ }) } else { next() }})new Vue({ router, store, render: h => h(App)}).$mount(’#app’)

這樣一個登陸畫面就實現了,具體的源碼可以參照:Vue實現登陸跳轉

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Vue
相關文章:
主站蜘蛛池模板: 西点培训学校_法式西点培训班_西点师培训_西点蛋糕培训-广州烘趣西点烘焙培训学院 | 球磨机,节能球磨机价格,水泥球磨机厂家,粉煤灰球磨机-吉宏机械制造有限公司 | MOOG伺服阀维修,ATOS比例流量阀维修,伺服阀维修-上海纽顿液压设备有限公司 | 无尘烘箱_洁净烤箱_真空无氧烤箱_半导体烤箱_电子防潮柜-深圳市怡和兴机电 | 游泳池设备安装工程_恒温泳池设备_儿童游泳池设备厂家_游泳池水处理设备-东莞市君达泳池设备有限公司 | 电销卡 防封电销卡 不封号电销卡 电话销售卡 白名单电销卡 电销系统 外呼系统 | 杭州火蝠电商_京东代运营_拼多多全托管代运营【天猫代运营】 | 干粉砂浆设备_干混砂浆生产线_腻子粉加工设备_石膏抹灰砂浆生产成套设备厂家_干粉混合设备_砂子烘干机--郑州铭将机械设备有限公司 | 混合气体腐蚀试验箱_盐雾/硫化氢/气体腐蚀试验箱厂家-北京中科博达 | 合肥网络推广_合肥SEO网站优化-安徽沃龙First | 团建-拓展-拓展培训-拓展训练-户外拓展训练基地[无锡劲途] | 首页|专注深圳注册公司,代理记账报税,注册商标代理,工商变更,企业400电话等企业一站式服务-慧用心 | 西门子伺服控制器维修-伺服驱动放大器-828D数控机床维修-上海涌迪 | 谈股票-今日股票行情走势分析-牛股推荐排行榜 | 西安标准厂房_陕西工业厂房_西咸新区独栋厂房_长信科技产业园官方网站 | 工业冷却塔维修厂家_方形不锈钢工业凉水塔维修改造方案-广东康明节能空调有限公司 | 电子海图系统-电梯检验系统-智慧供热系统开发-商品房预售资金监管系统 | 楼承板-开闭口楼承板-无锡海逵楼承板 | 济南玻璃安装_济南玻璃门_济南感应门_济南玻璃隔断_济南玻璃门维修_济南镜片安装_济南肯德基门_济南高隔间-济南凯轩鹏宇玻璃有限公司 | 真空上料机(一种真空输送机)-百科| 不锈钢电动球阀_气动高压闸阀_旋塞疏水调节阀_全立阀门-来自温州工业阀门巨头企业 | 换链神器官网-友情链接交换、购买交易于一体的站长平台 | 瑞典Blueair空气净化器租赁服务中心-专注新装修办公室除醛去异味服务! | 机器视觉检测系统-视觉检测系统-机器视觉系统-ccd检测系统-视觉控制器-视控一体机 -海克易邦 | 二手电脑回收_二手打印机回收_二手复印机回_硒鼓墨盒回收-广州益美二手电脑回收公司 | 宝元数控系统|对刀仪厂家|东莞机器人控制系统|东莞安川伺服-【鑫天驰智能科技】 | 工业冷却塔维修厂家_方形不锈钢工业凉水塔维修改造方案-广东康明节能空调有限公司 | 印刷人才网 印刷、包装、造纸,中国80%的印刷企业人才招聘选印刷人才网! | AGV叉车|无人叉车|AGV智能叉车|AGV搬运车-江西丹巴赫机器人股份有限公司 | 河南不锈钢水箱_地埋水箱_镀锌板水箱_消防水箱厂家-河南联固供水设备有限公司 | 红立方品牌应急包/急救包加盟,小成本好项目代理_应急/消防/户外用品加盟_应急好项目加盟_新奇特项目招商 - 中红方宁(北京) 供应链有限公司 | 上海小程序开发-上海小程序制作公司-上海网站建设-公众号开发运营-软件外包公司-咏熠科技 | 定制异形重型钢格栅板/钢格板_定做踏步板/排水沟盖板_钢格栅板批发厂家-河北圣墨金属制品有限公司 | 武汉天安盾电子设备有限公司 - 安盾安检,武汉安检门,武汉安检机,武汉金属探测器,武汉测温安检门,武汉X光行李安检机,武汉防爆罐,武汉车底安全检查,武汉液体探测仪,武汉安检防爆设备 | 成都亚克力制品,PVC板,双色板雕刻加工,亚克力门牌,亚克力标牌,水晶字雕刻制作-零贰捌广告 | PC构件-PC预制构件-构件设计-建筑预制构件-PC构件厂-锦萧新材料科技(浙江)股份有限公司 | 贵州自考_贵州自学考试网| 餐饮加盟网_特色餐饮连锁加盟店-餐饮加盟官网 | 谷歌关键词优化-外贸网站优化-Google SEO小语种推广-思亿欧外贸快车 | 江苏南京多语种翻译-专业翻译公司报价-正规商务翻译机构-南京华彦翻译服务有限公司 | 温州中研白癜风专科_温州治疗白癜风_温州治疗白癜风医院哪家好_温州哪里治疗白癜风 |