promise compatible browser problems

1, ES6 compatible issues

1. In the project, the Promise object of ES6 is used, and the code runs normally in Google browser. In the compatibility mode of 360 browser, IE kernel does not support Promise.

2. Support of ES6 promise found through can i use website https://caniuse.com/)

 

3. If the Promsie object is used in the project, the solution is to use the third-party plug-in bluebird.js (GitHub address: https://github.com/petkaantonov/bluebird)

4. Conclusion: the native Promise of ES6 is encapsulated in bluebird, which solves the problem of browser compatibility

2, Browser compatible with IE kernel

Introduce < script SRC = "https://cdn.polyfill.io/v2/polyfill.min.js" > < / script >

Or < script type = "text / JavaScript" SRC = "https://cdn.polyfill.io/v2/polyfill.min.js? Features = ES6" > < / script >

function menuType(){
		menuA = this;
		var promise = new Promise(function(resolve, reject){
			wilddog.sync().ref('').orderByKey().once('value', function (snapshot) {
			    var list = snapshot.val();
		        $("#leftNav nav").empty();
		        var html = "";
		        $.each(list, function (i, n) {
		        	menuA.menuArr.push(i);
		        	menuA.contentArr.push(n.total);
		            html += "<span class='fenlei' title='" + n.title + "' value="+i+">" + n.title + "</span>";
		        })
		        $("#leftNav nav").html(html);		        
			  	resolve(menuArr);
			});
		});
		return promise;
	}
menuType().then(function(menuArr){
// Video query all
videoAll();
})
async function videoAll() {
		// Video recommended by experts
		$("#expert").empty();
		wilddog.sync().ref('').orderByChild('update_time').limitToLast(homepagesize).on("child_added", function (recommenddata) {
		    let n = recommenddata.val();
		    let i = recommenddata.key();
	        var rechtml = "";
	        rechtml += '<div class="flex-box" clickhref="'+ i + '" value="' + i + '"><span class="preview-box"><i class="icon icon-video-play"></i><img src="http://' + n.thumbnail + '" /></span>'+
	        			'<h4 class="video-title">' + n.description + '</h4>'+
	        			'<span class="corner">Free membership</span><span class="look">'+
	        			'<i class="icon icon-eye"></i>'+ n.clickamount + 'Man learns</span></div>';
	        $("#expert").prepend(rechtml);
		});
		// Video recomm end ed by experts
		// General video
		var menulength = menuArr.length;
		$(".djt").empty();
		for (var j=0; j<menulength; j++)
		{
			// Category node name found
			mtype = menuArr[j];
			var cnum = await countnum(mtype); 
			// General video acquisition
			details(mtype,cnum)
		}
	}

3, Project development environment (compatible in older browsers)

1. Download dependency first, needless to say

npm i es6-promise --save-dev

2. Introduce ES6 promise package into / src/main.js, and use

import promise from 'es6-promise';
 
// Promise compatible
promise.polyfill();

 

 

Tags: IE github snapshot Google

Posted on Fri, 03 Jan 2020 11:29:29 -0800 by Thrakorzog