(这个看这一篇博客)vue h5 微信授权
npm install 'vue-wechat-title' --save
import VueWechatTitle from 'vue-wechat-title'
Vue.use(VueWechatTitle)
import Vue from 'vue'
import VueRouter from 'vue-router'
import { Toast } from 'vant';
Vue.use(VueRouter)
const routes = [
{
path: '/',
redirect: '/login'
},
{
path: '/login',
name: 'Login',
meta: {
title: '登录',
requireAuth: true
},
component: () => import( '../views/Login.vue')
},
{
path: '/index',
name: 'Index',
meta: {
title: '首页',
requireAuth: true
},
redirect: '/index/home',
component: () => import( '../views/Index/Index.vue'),
children:[
{
path: 'home',
name: 'Home',
meta: {
title: '首页',
requireAuth: true
},
component: () => import( '../views/Home/Home.vue')
},
{
path: 'back',
name: 'back',
meta: {
title: '首页',
requireAuth: true
},
component: () => import( '../views/Back/Back.vue')
},
{
path: 'kebiao',
name: 'Kebiao',
meta: {
title: '课表',
requireAuth: true
},
component: () => import( '../views/Kebiao/Kebiao.vue')
},
{
path: 'chengji',
name: 'Chengji',
meta: {
title: '成绩',
requireAuth: true
},
component: () => import( '../views/Chengji/Chengji.vue')
},
{
path: 'shezhi',
name: 'Shezhi',
meta: {
title: '设置',
requireAuth: true
},
component: () => import( '../views/Shezhi/Shezhi.vue')
},
]
},
{
path: '/about',
name: 'About',
component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
}
]
const router = new VueRouter({
mode: 'history',
routes
})
router.beforeEach((to, from, next) => {
let password=localStorage.getItem("password");
let mima=localStorage.getItem("text");
//有账号和密码,并且已经授权获取用户信息,或者在登录页面,就放行路由
if(mima&&password &&localStorage.getItem("userinfo") ||to.path == "/login"){
console.log("路由跳转了")
next();
//没有账号密码,就拦截路由,跳转到登录页面重新输入
}else if(!mima|| !password){
Toast("请输入账号密码")
next("/login");
//没有用户信息,说明没有授权,重新返回登录页面,再次授权
}else if(!localStorage.getItem("userinfo")){
Toast("请重新授权")
next("/login");
}
})
export default router
<div id="app">
<router-view v-wechat-title='$route.meta.title'/>
div>
npm install 'weixin-js-sdk' --save
npm install 'vue-touch' --save
import wx from 'weixin-js-sdk'
import VueTouch from 'vue-touch'
Vue.use(VueTouch, {name: 'v-touch'})
v-on:swipeleft="left" v-on:swiperight="right"
<v-touch v-on:swipeleft="left" v-on:swiperight="right" >
v-touch>
left(){
console.log("左滑")
wx.closeWindow()
},
right(){
console.log("右滑")
//这个使用了import wx from 'weixin-js-sdk',在微信中会关闭当前页面
wx.closeWindow()
},