安装路由
npm i [email protected] -S
创建路由模块 src/router/index.js
import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
const router = new VueRouter()
export default router
3.main.js
挂载路由
// 1.导入模块
import router from '@/router'
new Vue({
render: h => h(App),
router // 2.挂载路由
}).$mount('#app')
router/index.js
路由模块声明路由规则// 1.导入登录组件
import MyLogin from '@/components/MyLogin.vue'
const router = new VueRouter({
routes: [
// 2.登录的路由规则
{
path: '/login',
component: MyLogin
}
]
})
App.vue
组件启用 路由占位符
<div>
<!-- 路由占位符 -->
<router-view></router-view>
</div>
const router = new VueRouter({
routes: [{
// 路由重定向
path: '/',
redirect: '/login'
},
// 登录的路由规则
{
path: '/login',
component: Login
}
]
})
1. `MyLogin.vue` 输入框双向绑定
- trim 去除多余空格
<input type="text" class="form-control ml-2" id="username" placeholder="请输入登录名称" autocomplete="off" v-model.trim="username" />
<input type="password" class="form-control ml-2" id="password" placeholder="请输入登录密码" v-model.trim="password" />
data() {
return {
username: '',
password: ''
}
}
<button type="button" class="btn btn-secondary mr-2" @click="reset">重置</button>
// 重置
reset() {
this.username = ''
this.password = ''
},
<button type="button" class="btn btn-primary" @click="login">登录</button>
// 登录
login() {
if (this.username === 'admin' && this.password === '123456') {
localStorage.setItem('token', 'Bearer xxxx')
this.$router.push('/home')
} else {
localStorage.removeItem('token')
}
}
Token 认证时 token格式
Bearer
Bearer + 空格 固定写法
声明后台主页/home
的路由规则
router/index.js
// 导入主页组件
import Home from '@/components/MyHome.vue'
// 后台主页
{
path: '/home',
component: Home
}
MyHome.vue
挂载组件
<div class="home-container">
<!-- 头部区域 -->
<MyHeader></MyHeader>
<!-- 页面主体区域 -->
<div class="home-main-box">
<!-- 左侧边栏 -->
<MyAside></MyAside>
<!-- 右侧主体区域 -->
<div class="home-main-body">
</div>
</div>
src/components/subcomponents/MyHeader.vue
<button type="button" class="btn btn-light" @click="logout">退出登录</button>
// 退出登录
logout() {
localStorage.removeItem('token')
this.$router.push('/login')
}
访问权限控制 全局前置守卫
/src/router/index.js
router.beforeEach(function(to,from,next){
if (to.path === '/home') {
// 要访问后台主页,需要判断是否有 token
const token = localStorage.getItem('token')
if (token) {
next()
} else {
// 没有登录,强制跳转到登录页
next('/login')
}
} else {
next()
}
})
MyAside.vue
<li class="menu-item">
<router-link to="/home/users">用户管理</router-link>
</li>
<li class="menu-item">
<router-link to="/home/rights">权限管理</router-link>
</li>
<li class="menu-item">
<router-link to="/home/goods">商品管理</router-link>
</li>
<li class="menu-item">
<router-link to="/home/orders">订单管理</router-link>
</li>
<li class="menu-item">
<router-link to="/home/settings">系统设置</router-link>
</li>
MyHome.vue
子路由占位符 <!-- 右侧主体区域 -->
<div class="home-main-body">
文章浏览阅读670次。oracle常用经典SQL查询 常用SQL查询: 1、查看表空间的名称及大小 selectt.tablespace_name, round(sum(bytes/(1024*1024)),0) ts_sizefromdba_tablespaces t, dba_data_files dwheret.tablespace_name = d.tablespace_name_用oracle sql语句 查询 热门t
文章浏览阅读666次。需求:用HttpURLConnection模拟上传图片并把图片的名称也要传递过去.简单分析:写入流的时候依次写入 图片名称 + "|" 分隔符 + 图片流然后服务器接收的再处理流.分别取出图片名和图片./** *//** * 上传方法 * 返回上传完毕的文件名 * * */ public String upload(File f) { ..._httpurlconnection上传图片
文章浏览阅读3.3k次。下载对应的版本到本地,然后pip install xxxx.wheel安装即可。_error: could not build wheels for wxpython, which is required to install pyp
文章浏览阅读1.4w次,点赞6次,收藏73次。几种无线通讯介绍与比较(蓝牙,WiFi,IrDA,NFC,Zigbee,UWB)_蓝牙 wifi zigbee nfc比较
文章浏览阅读359次。prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.6//x86_64-linux/include/c++/4.6/bits/basic_string.h:270: error: unsupported reloc 43prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.6//x86_64-linux/include/c++/4.6/bits/basic_string.h:270: error:_error: unsupported reloc 43
文章浏览阅读81次。题目描述在一个 n * m 的二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个高效的函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。示例:现有矩阵 matrix 如下:[ [1, 4, 7, 11, 15], [2, 5, 8, 12, 19], [3, 6, 9, 16, 22], [10, 13, 14, 17, 24], [18, 21, 23, 26, 30]]给定 targe..._java 二维数组 时间复杂度 ( + )o(n+m)
文章浏览阅读819次,点赞13次,收藏8次。SIT报告
文章浏览阅读413次。最近Xcode版本升级到10之后,运行项目时出现library not found for -lstdc++.6.0.9错误。项目中有用到libstdc++、libstdc++.6、libstdc++6.0.9这三个库文件的Xcode10谨慎更新报错原因是:使用之前的Xcode版本开发的项目中有用到libstdc++、libstdc++.6、libstdc++6.0.9这三个库文件,而Xcod..._-lstdc++.6.0.9
文章浏览阅读2.2k次。1.在app.config.js中的window配置项的内容替换为:"navigationStyle":"custom"custom表示自定义导航栏,但会保留右上角胶囊按钮。window: { // backgroundTextStyle: 'light', // navigationBarBackgroundColor: '#fff', // navigationBarTitleText: 'WeChat', // navigationBarTextStyle: _taro navigationstyle
文章浏览阅读1.1k次,点赞21次,收藏13次。本系列文章致力于用最简单的语言讲解Transformer架构,帮助朋友们理解它的强大,本文是第六篇:Transformer自注意力机制图文详解。_transformer 自注意力机制
文章浏览阅读2.2k次,点赞21次,收藏20次。【代码】安卓逆向学习之ADB的配置和使用及刷机root。_adb root
文章浏览阅读788次。若有代数式3ae/bc,则不正确的C语言表达式是( )更多相关问题Python字典支持双向索引。正则表达式模块re的_______方法用来在字符串开始处进行指定模式的匹配。Python字典中的“键”可以是元组。Python字典中的“键”不允许重复。表达式sorted([111, 2, 33], key=lambda x: len(str(x))) 的值为________________。已知 x ..._代数式3ae/bc,如何计算