場景:Vue 微信商城頁面
功能需求:前端請求code前端
微信後臺相關設置都是後臺同事設置好appid及ip白名單vue
Vue main.js 先設置路由攔截判斷,未登陸前往author.vue 頁面進行受權微信
router.beforeEach((to, from, next) => { let code = () => { // 獲取暫存的code信息 return window.sessionStorage.getItem("weCode") } if(!code){ if (to.path !== '/author') { // 暫存進入連接,以便獲取code後返回 window.localStorage.setItem('authUrl', to.fullPath) next("/author") return false } } next() })
author.vuesession
未完待續