我是用的是uniapp的renderjs,经测试,是在guide.js中发现使用jsonp请求//cf.aliyun.com/nvc/nvcPrepare.jsonp触发了script的onerror,onerror回调参数为:
{
"isTrusted": true,
"NONE": 0,
"CAPTURING_PHASE": 1,
"AT_TARGET": 2,
"BUBBLING_PHASE": 3,
"type": error,
"target": [object HTMLScriptElement],
"currentTarget": [object HTMLScriptElement],
"eventPhase": 2,
"bubbles": false,
"cancelable": false,
"defaultPrevented": false,
"composed": false,
"timeStamp": 607.3999999789521,
"srcElement": [object HTMLScriptElement],
"returnValue": true,
"cancelBubble": false,
"path": [object HTMLScriptElement],
[object HTMLHeadElement],
[object HTMLHtmlElement],
[object HTMLDocument],
[object Window],
"composedPath": function composedPath() {
[native code]
},
"stopPropagation": function stopPropagation() {
[native code]
},
"stopImmediatePropagation": function stopImmediatePropagation() {
[native code]
},
"preventDefault": function _() {
window.__needNotifyNative__ && "touchmove" == this.type && (window.__needNotifyNative__ = t.execSync(e.webview.currentWebview(), "needTouchEvent", [])), l.oldPreventDefault.call(this)
},
"initEvent": function initEvent() {
[native code]
},
}
3 个回复
花志飘零 (作者)
有没有什么思路去解决这个问题
花志飘零 (作者)
引入awsc文件,即使用新版的集成放大就行
h***@qq.com
虽然帮不上提问者了, 不过还是记录下以帮助后来还要用这个功能的人吧
出现 getNVCVal is not defined 的原因是app获取外部脚本失败了.
失败的原因是这里加载的外部脚本都是 "//g.alicdn.com/xxx" 这样的地址, 在浏览器中这没有问题, 因为浏览器有url地址, 不是http就是https的, 而app中很有可能是类似 "file:///"开始的地址, 这样加载的路径就变成了 "file://g.alicdn.com/xxx" 而加载失败.
好在加载外部js的代码都是在guide.js里, 在设置src的地方判断下, 如果是 "//"开头的在前面加上 "https:"就行了
修改代码节选
e.exports={jsonp:function(e){var t=("jsonp_"+Math.random()).replace(".",""),n=c.getElementsByTagName("script")[0],o="";e.data?(e.data[e.callback]=t,o+=r(e.data)):o+=e.callback+"="+t;var s=c.createElement("script");n.parentNode.insertBefore(s,n),a[t]=function(t){e.success&&e.success(t)},s.src= (e.url.indexOf('//')===0?"https:":'')+ e.url+(-1==e.url.indexOf("?")?"?":"&")+o},loadScript:function(e){var t=c.getElementsByTagName("script")[0],n=c.createElement("script");t.parentNode.insertBefore(n,t),n.src= (e.indexOf('//') === 0?"https:":"")+ e}}