weex v1.0.5 用navigator跳转本地js,怎么跳

就例如简单一个按钮,点击跳转下一个js。我的baseUrl不知道怎么获取,网上说的

var bundleUrl = this.$getConfig().bundleUrl;
bundleUrl = new String(bundleUrl); 
var nativeBase;
        var isAndroidAssets = bundleUrl.indexOf('file://assets/') >= 0;

        var isiOSAssets = bundleUrl.indexOf('file:///') >= 0 && bundleUrl.indexOf('myAPP.app') > 0;
        if (isAndroidAssets) {
          nativeBase = 'file://assets/';
        }
        else if (isiOSAssets) {
          nativeBase = bundleUrl.substring(0, bundleUrl.lastIndexOf('/') + 1);
        }
        else {
          var host = 'localhost:12500';
          var matches = /\/\/([^\/]+?)\//.exec(this.$getConfig().bundleUrl);
          if (matches && matches.length >= 2) {
            host = matches[1];
          }
          nativeBase = 'http://' + host + '/' + this.dir + '/dist/';
        }
        var h5Base = './index.html?page=./' + this.dir + '/dist/';
        //Native端
        var base = nativeBase;
        //H5端
        if (typeof window === 'object') {
          base = h5Base;
        }
        this.baseURL = base;
获取不到
        

jump: function() {
                console.log('will jump')
                navigator.push({
                    url: this.baseUrl+'foo.js',
                    animated: "true"
                }, event => {
                    modal.toast({ message: 'callback: ' + event })
                })

    },
阅读 4.5k
1 个回答

https://github.com/apache/inc...
请参考这个方法

这个方法有缺陷的,你是 weex run web 还是weex src命令,如果是weex run web,需要将var h5Base = './index.html?page=./' + this.dir + '/dist/';改成 var h5Base = './weex.html?page=dist/';俺正很多坑,注意一下吧。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进