javascript - How does a .vue file reference a js file or .vue file that is called at the beginning and supports this.xxx
伊谢尔伦
伊谢尔伦 2017-07-05 10:48:35
0
3
653

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

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(3)
ringa_lee

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

为情所困

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.

黄舟

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template