uniapp向webview注入JS代码文件
1code
		onReady() {
			// #ifdef APP-PLUS
			var self = this;
			var currentWebview = this.$scope
		.$getAppWebview(); //此对象相当于html5plus里的plus.webview.currentWebview()。在uni-app里vue页面直接使用plus.webview.currentWebview()无效,非v3编译模式使用this.$mp.page.$getAppWebview()
			setTimeout(function() {
				wv = currentWebview.children()[0];
				wv.addEventListener(
					'progressChanged',
					function(e) {
						wv.canBack(function(e) {
							self.canBack = e.canBack;
						});
					},
					false
				);
				//https://www.monxin.com/public/test.js
				  wv.addEventListener("loaded", function() {  
				       console.log('wv:loaded');              
				  });  
								
				setTimeout(function(){
					wv.evalJS(
					    "var scri = document.createElement('script');	scri.async='async';	scri.src='https://www.monxin.com/public/test.js?"+Math.random()+"';document.getElementsByTagName('html')[0].appendChild(scri);"
					); 
				},2000)				
				
				
			}, 500); //如果是页面初始化调用时,需要延时一下
			// #endif
		}
本页由《梦行文档》生成

 

name完成
30