国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術(shù)文章
文章詳情頁

關(guān)于android 集成weex 加載js 時報(bào)ReferenceError: window is not defined

瀏覽:182日期:2024-08-17 16:08:30

問題描述

關(guān)于android 集成weex 加載js 時報(bào)ReferenceError: window is not defined如題將.we 文件npm run build 后將js拷貝到android asset文件下面,按照官方的集成步驟運(yùn)行android studio 頁面空白 控制臺報(bào) 04-11 11:48:50.946 3321-3345/com.weex.sample E/jsengine: ReportException :undefined:2212: ReferenceError: window is not defined 04-11 11:48:50.949 3321-3345/com.weex.sample E/jsengine: ReportException : ReferenceError: window is not defined

at Object.exports.getBaseUrl (eval at Cn ((weex):2:4300), <anonymous>:2212:21) at Yt.created (eval at Cn ((weex):2:4300), <anonymous>:104:26) at (weex):1:27665 at Array.forEach (native) at Yt.zt [as $emit] ((weex):1:27643) at new Yt ((weex):1:29107) at ln ((weex):2:98) at a ((weex):2:2870) at Object.module.exports.type (eval at Cn ((weex):2:4300), <anonymous>:67:2) at __webpack_require__ (eval at Cn ((weex):2:4300), <anonymous>:26:30)

04-11 11:48:50.950 3321-3345/com.weex.sample E/weex: reportJSException >>>> instanceId:2, exception function:createInstance, exception:ReferenceError: window is not defined

問題解答

回答1:

在原生層面window對象不支持

回答2:

找到答案了 是在頁面跳轉(zhuǎn)時獲取頁面uri階段出問題了 使用了window.location.host andorid 這邊不認(rèn)識這個window

exports.getBaseUrl = function (bundleUrl, isnav) {

bundleUrl = new String(bundleUrl);var nativeBase;var isAndroidAssets = bundleUrl.indexOf(’file://assets/’) >= 0;var isiOSAssets = bundleUrl.indexOf(’file:///’) >= 0 && bundleUrl.indexOf(’WeexDemo.app’) > 0;if (isAndroidAssets) { nativeBase = ’file://assets/dist/’;}else if (isiOSAssets) { nativeBase = bundleUrl.substring(0, bundleUrl.lastIndexOf(’/’) + 1);}else { // var host = window.location.host; 這個在瀏覽器中可以用 var host; var matches = ///([^/]+?)//.exec(bundleUrl); if (matches && matches.length >= 2) {host = matches[1]; } // alert('er:::'+host); //此處需注意一下,tabbar 用的直接是jsbundle 的路徑,但是navigator是直接跳轉(zhuǎn)到新頁面上的. // if (typeof window === ’object’) { // nativeBase = isnav ? ’http://’ + host + ’/index.html?page=./dist/’ : ’/dist/’; // } else { // nativeBase = ’http://’ + host + ’/dist/’; // }}// alert('nativeBase: '+nativeBase);nativeBase='http://'+host+'/dist/';return nativeBase;

};

相關(guān)文章:
主站蜘蛛池模板: 巴楚县| 深水埗区| 沁水县| 蓝田县| 拉孜县| 湖州市| 西华县| 定安县| 高唐县| 天门市| 马尔康县| 桐梓县| 慈利县| 天津市| 玛沁县| 安阳市| 尼玛县| 滦平县| 襄汾县| 安义县| 师宗县| 台北县| 玉龙| 敦化市| 合川市| 固原市| 顺平县| 义马市| 南京市| 石楼县| 绥阳县| 张家口市| 娄烦县| 全南县| 重庆市| 三亚市| 贵阳市| 慈利县| 太康县| 临朐县| 樟树市|