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
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.