Home  >  Q&A  >  body text

javascript - Regarding development using axios and vue. When the mobile browser returns, it reads the cache and cannot execute js and vue components.

A mobile website has tested login restrictions on a page. If you are not logged in, you will go to the login page. However, when you reach the login page and press the return key, you can still return to the first page without reading any data or pictures. How can I do this? When he goes back, he refreshes the web page instead of reading the cached website

高洛峰高洛峰2662 days ago923

reply all(2)I'll reply

  • 滿天的星座

    滿天的星座2017-07-05 10:50:12

    The window.location.replace() parameter writes the routing address you want to jump to (this page will not generate a cache, and the browser will not have a back option. If you need to generate a back option, replace "replace" with assign);

    reply
    0
  • 给我你的怀抱

    给我你的怀抱2017-07-05 10:50:12

    If you use vue-router in your project, you can use router.beforeEach
    Refer to the code below

    router.beforeEach((to, from, next) => {
      store.commit('SET_MODULE', to.meta.module)
      if (to.matched.some(record => record.meta.requiresAuth === true)) {
        if (store.getters.token === '') { 
          next({
            path: '/sign',
            query: {redirect: to.fullPath}
          })
        } else {
          next()
        }
      } else if (to.matched.some(record => record.meta.requiresAuth === false)) {
        if (store.getters.token !== '') {
          next(to.query.redirect || '/m')
        } else {
          next()
        }
      } else {
        next()
      }
    })

    https://github.com/ycloud/cno...

    If vue-router is not used, you can put the login judgment in beforeCreate for detection

    reply
    0
  • Cancelreply