鍍金池/ 問答/HTML/ week navigator.push 跳轉(zhuǎn)過去顯示的是js 文件的內(nèi)容

week navigator.push 跳轉(zhuǎn)過去顯示的是js 文件的內(nèi)容

用week navigator.push 寫了個頁面跳轉(zhuǎn)的demo,跳轉(zhuǎn)過去是顯示的對應(yīng)js

jump(){
      console.log(213)
      this.baseURL = 'http:/dist/components/detail.js'
      var params = {
          'url':  this.baseURL,
          'animated' : 'true',
      }
      navigator.push(params,function(){
      });
  }
  

clipboard.png

clipboard.png
有沒有大神可以解釋下是什么原因

回答
編輯回答
孤星

你的baseUrl感覺有問題,以下是我們的做法給你參考:

common.js里面的公用方法:
exports.bundleUrl = function (self) {

var bundleUrl = self.$getConfig().bundleUrl;
return bundleUrl;

};
//判斷系統(tǒng),安卓返回'android',ios返回'iOS',h5返回'web'
exports.androidOrIos = function (self) {

return self.$getConfig().env.platform;

};
//獲取url地址
exports.getBaseUrl = function (self) {

var androidOrIos = this.androidOrIos(self);
var bundleUrl = this.bundleUrl(self);
var isHttp = bundleUrl.indexOf('http://') >= 0;
var nativeBase;
if (isHttp) {
    var i = bundleUrl.indexOf('/dist/');
    nativeBase = bundleUrl.slice(0, i) + '/dist/';
} else {
    if (androidOrIos == 'android') {
        nativeBase = 'file://assets/dist/';
    } else if (androidOrIos == 'iOS') {
        nativeBase = bundleUrl.substring(0, bundleUrl.lastIndexOf('dist/') + 5);
    } else {
        var host = 'localhost:12580';
        var matches = /\/\/([^\/]+?)\//.exec(bundleUrl);
        if (matches && matches.length >= 2) {
            host = matches[1];
        }
        nativeBase = 'http://' + host + '/example/build/';
    }
}

var h5Base = './index.html?page=./example/build/';

// in Native
var base = nativeBase;
if (typeof window === 'object') {
    base = h5Base;
}
return base;

};
//跳轉(zhuǎn)到指定url頁面
/**
*url 請求地址,前綴已添加,為baseUrl,傳值如:'login/login';
*param為需帶參數(shù),傳值如:'name1=value1&name2=value2'
*callback為回調(diào)函數(shù),傳值如:function(){};
**/
exports.jump = function (self, url, param, callback) {

var navigator = weex.requireModule('navigator');
var baseUrl = this.getBaseUrl(self);
var param = param ? param : '';
var url = {'url': baseUrl + url + '.js?' + param, 'animated': 'true'};
navigator.push(url, function (e) {
    if (callback) {
        typeof callback == 'function' && callback(res);
    }
});

}

在頁面調(diào)用:
import common from './common/common';
export default {

methods: {
    toTest() {
        common.jump(this, 'test/test');
    }
}

}

2017年3月8日 20:16