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

查看:413
本文介绍了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 })
                })

    },

解决方案

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/';俺正很多坑,注意一下吧。

这篇关于weex v1.0.5 用navigator跳转本地js,怎么跳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆