Before beforeEach mounts the instance again, router.js is invalid and cannot be redirected to other pages.

import Vue from "vue"
import App from "./App"
import router from "./router/router"

Vue.config.productionTip = false
// import { queryList } from "./api/index"
import util from "./util/util"
router.beforeEach((to, from, next) => {
  let code = util.getCode("code")
  alert(code)
  if (!code) {
    // util.weixinauth()
    console.log(1111)
  } else {
    // queryList({ code: code }).then(res => {
    //   console.log(res, 36)
    //   alert(res.data.openid + "" + res.data.nickname)
    // })
    console.log(2222)

    next()
  }
})

/* eslint-disable no-new */
new Vue({
  el: "-sharpapp",
  router,
  components: { App },
  template: "<App/>"
})

Mar.17,2022

router.beforeEach((to, from, next) => {
  let code = util.getCode('code')
  alert(code)
  if (!code) {
    // util.weixinauth()
    console.log(1111)
  } else {
    // queryList({ code: code }).then(res => {
    //   console.log(res, 36)
    //   alert(res.data.openid + '' + res.data.nickname)
    // })
    console.log(2222)
  }


  next()
})
Menu