Home  >  Q&A  >  body text

javascript - How does a .vue file reference a js file or .vue file that is called at the beginning and supports this.xxx

Now it is a WeChat webpage. We have a code to determine whether to log in and whether it is WeChat, but we don’t know how to put it on all pages. Now it is very troublesome to write it once for all pages

     if( localStorage.getItem("login")){
          this.memberId = JSON.parse(localStorage.getItem("login")).id
        } 

There is memberId in the data of the page. All pages need to be judged as soon as they enter the page. The value can also be brought into this.memberId. Please find a method

伊谢尔伦伊谢尔伦2662 days ago620

reply all(3)I'll reply

  • ringa_lee

    ringa_lee2017-07-05 10:50:35

    If you use vue-router, you can put the code in the
    router.beforeEach hook function

    reply
    0
  • 为情所困

    为情所困2017-07-05 10:50:35

    You can use mixins.

    Add a memberId data to the mixin uniformly, and determine the login value of localStorage in created or other hooks and assign a value to memberId.

    reply
    0
  • 黄舟

    黄舟2017-07-05 10:50:35

    After obtaining the memberID, you can put the memberId in the request header, which saves trouble.

    reply
    0
  • Cancelreply