scenario:
fetch tocken token
question:
fetch async await
scenario:
fetch tocken token
question:
fetch async await
my solution is to use high-order components + redux to solve the problem.
first of all, all the interfaces go to redux, where the data is normal, where should dispatch go to dispatch. If login fails dispatch A failed login action, then handles the login problem in the high-level component, if the login state is not found, then jump to the login page and do nothing if there is a login state.
Note: do not dispatch, the login page itself in reducer, do not be wrapped by high-level components
and then there is the question of aesthetics. WithRouter (connect (state= > state) (LoginHOC (YourBusiness);
is just a little longer.
in fact, I just casually answer, redux management interface, it is true that the page view can be completely decoupled, but you know how troublesome it is to hit a toast with an interface exception. Dispatch to redux, in a few seconds and a cancelToast in dispatch
< hr >I'm also waiting for better interface management. Sometimes contradictory reuse lines think that this decoupling, the introduction of a tripartite state and subscription, and then map to their own state, uncoupling will certainly cause inconvenience.
ps: some colleagues in the brain circuit who are light and strange, let the ajax module accept a this, and then be able to manipulate the page. Oh, my God. That's not as good as Vue's mixin idea.
1. Login will not be returned many times. If the first request you make determines that token is invalid and adjusts it to the login page, then none of the subsequent requests will execute
2. Multiple requests may have been made before returning, but the return will only be executed once
I guess your scenario is client routing and fetch initiated by multiple components on the page.
it is recommended to encapsulate the fetch function as a public object, and each component can call it uniformly, and the identity exception can be handled uniformly, so that it can be easily handled when the second exception is about to jump. The easiest way you can set a flag, the first jump behind the true, do not jump. Then the identity is processed and the flag is set to false.
Let me add that finally promise.all can basically solve this problem
various methods have been tried, including the simplest way to disable the thouchmove event directly. Has the Wechat browser under ios been unable to stop the rebound? ...
In the vue-cli project, I directly introduced the particls library into index.html, and the related files are placed in the static directory . <div id="particles-js">< div> <script type="text javascript" src="s...
I am a novice. At present, I have encountered some confusion when learning set data types in Es6, as follows: in the Es6 about Ruan Yifeng, it is mentioned that set types can be used to intersect and judge sets, but I have tried it unsuccessfully. ...
the article on Wechat s official account crawled through python at the backend found that the video in the article could not be played, and the video was nested in iframe, as shown in <iframe class="video_iframe" data-vidtype="2"...
currently working on a saas platform what kind of architecture can meet the following requirements: Separation of front and rear ends flexible selection of front-end technology, less historical burden, convenient maintenance, and organizational n...
read what a big guy wrote: Function.prototype.bind = Function.prototype.bind || function (context) { var me = this; var args = Array.prototype.slice.call(arguments, 1); var F = function () {}; F.prototype = this.prototype; var bound...
the text matched by the search box above an article is highlighted to realize the idea. ...
want to use vue2.0 to develop a small web application for the company, running on the mobile side. How can the above functions be achieved? ...
A quick implementation is generally as follows: Function.prototype.bind = function (context) { var me = this; var argsArray = Array.prototype.slice.call(arguments); return function () { return me.apply(context, argsArray.slice(1)) ...
as shown in the picture, after clicking the button, you append a new button in document.body. How did the new button be updated to the page? will the original button be rendered again? ...
I just got in touch with Mini Program developer and recently encountered this problem when I wrote the demo, of a music player. After I returned to the list page from the playback page (or to the home page), I entered the playback page from the entrance...
const obj = { name: " jsCoder", skill: ["es6", "react", "angular"], say: function () { for (var i = 0, len = this.skill.length; i < len; iPP) { setTimeout(function(){ ...
as shown in the figure above, use css to make a magnification effect when a mouse passes over a square, but as soon as you enlarge a square, the square next to it will be squeezed out or squeezed into the next row. Is there any way to fix the enlarge...
there is a bypass Filter in proxyTable. How do I use it? Is it the return path? Or return true false ...
there is such a requirement, as shown in the figure are four menu buttons. The four menu icons here are not vector icons similar to Font Awesome, but pictures in png format, namely f.png, u.png, s.png, and p.png. demand: clicking on the correspondi...
1. At the beginning, it was 2. . Why is this? ...
how do Vue projects built with Nuxt.js share header and footer files? only files with section contents are placed in the page directory. Navigation bars and footers and every time you jump to a new route, navigation doesn t have to be reloaded. Gods, ...
I have a vegetable chicken at the front end. Recently, there is a new demand for the company s project, which has been maintained by others before. the front end uses a framework built by pHp and uses the memcached plug-in. After the project runs, ,...
In the case of MDN, the local operation does not print the geographical location, nor does it report an error. Why? Ask for instructions at the beginning, the PC side has been returning a timeout. It may be because the PC side does not support it. Afte...
there is a benchmarks directory in some open source projects, such as vue , which is very popular now. The literal translation of benchmark means benchmark test. It seems that some functional performance tests can be done. given that there is a test di...