Some time ago in the small circle and everyone to share my feelings, H5 instead of the client for mobile development, is a major trend. For a long time in the future, it is the world of hybrid applications. However, H5 write mobile page, that is definitely a step a pit rhythm ah, do a good job of the compatibility of each device will be the important mission of the front-end er. Today to everyone to send a collection, is my recent development encountered in some pits, make a record, also give you some experience.
1.
Babel-polyfill honestly Add. Now many projects are written with ES6, ES6 on the mobile side of the compatibility is also born better. Some students dislike Polyfill file too large (compression will also close to 100KB) will not be cited, anyway, the method used is not much.
However, recently found in the Meizu mobile phone reported wrong, look for reasons found that there is no Array.includes method, and the project is what I said not cited Babel-polyfill situation. So, for the sake of insurance, let's be honest. Of course, you can introduce the corresponding method as needed, so the cost is high, and you can't foresee which method the project will use in the future.
2.
Colleague feedback, a page on iOS, the input box to lose something to flash back. I was surprised how an input box could be used to blow up the application.
After the investigation, the reason is surprising. The scenario is this: when you click on the Input tab, you can determine whether to add ReadOnly attributes based on some logic. On the phone, the click action may have a delay, the keyboard has been bounced before the logical decision takes effect, and then input is set to ReadOnly. At this point, if you enter something with the keyboard, the system will flash back! Yes, it's a flash back. Because you're writing something in a readonly input box.
Of course, this is also a logical problem, a input box, should be clicked before it is the ReadOnly property OK.
3.
foreach to Loop nodelist is not reliable. Queryselectorall returns the NodeList type, and foreach is the method above the array. Most browsers are compatible, and using foreach to loop nodelist such arrays of classes can also work.
However, is not hundred hundred, found in vivo mobile phone on the no, direct error. So you have to be honest with the for loop to fetch. Some people say that you can turn the class array into a group, but I think it's an extra overhead to go for a loop.
4.
Fixed positioning is not fully supported on iOS. It was known that iOS did not support fixed positioning and was supported in later versions of the system.
But in a recent test, when the contents of the fixed element are many, both DOM nodes are nested very much, the fixed element is slipping away under a disorderly operation! Visible in the latest iOS10, fixed support is not perfect AH.
So I usually use absolute positioning + local div scrolling to achieve fixed positioning.
5.
Click to be able to tap, but also to take the risk. Click event point through the phenomenon, do mobile development of the students should know that a few years ago on-line also a lot of analysis articles. In fact, the core problem is that in the event of the distribution process, the current click element disappears suddenly, causing the event to be "grafted" on other elements.
One of the most recently encountered pits is when an element binds to the Touchstart event, and if the page pops up a layer during the click, the Click event also occurs on top of the layer, feeling like it's on the run.
6.
This problem, is to solve 5 and lead to. I tried to add a preventdefault to the Touchstart event, and the whole page was rolling. The reason is to disable the default scroll action. It seems to be unable to add preventdefault to the Touchstart event.
7.
Does Vue have a performance flaw on iOS? The project uses Vue as a whole and discovers certain actions that have a noticeable delay on iOS. I dare not diagnose is Vue's problem, just on the appearance to do summary.
Data stored in the store, watch in the component, and find the update to be slow.
Frequently modify the data binding, such as audio progress event, the page when the style binding, when the system multiple keyboard popup, the real-time update will be invalid, I have to manually manipulate the DOM.
A modifier is used for the event, such as. Stop/.prevent, and there is a noticeable delay in the execution of the listener function.
8.
Press the Home button to enter the background after the situation. Both iOS and Android need to be aware that there are things you might want to deal with: whether the delay delay is still executing, whether the audio will continue to play, and whether the promise chain is continuing to execute.
If the page has the above operation, you need to pay attention to, when the home key to enter the background, and then return to the page is still normal.
The corresponding approach, there is the page Visibility API, but to consider compatibility. It is better to have the shell to provide the API, which is more secure.
9.
The destruction of the Vue component. The Vue component has a $destroy method, generally not, but if it is to be used, notice that it simply destroys the Vue instance. The related status stored in the store needs to be reset manually. The HTML node on the page needs to be removed manually.
10.
Vuex Automatic registration issues. This is not related to the mobile side, but also encountered, say it together.
Vuex will automatically detect if there is a global vue variable, and some will automatically register. If you use it again in your code, you will get an error. I tried to find out if Vue had registered the Vuex, but I didn't get the method. Finally, we have to judge this: if (window. Vue && window. VUEX). This means that Vuex must have been registered.
Mobile End Pit Collection