weex使用navigator跳转界面

本文详细介绍了在Weex框架下如何通过appUtils.js文件中的getUrl函数进行URL组装,以及如何利用navigator模块实现界面的跳转。通过具体代码示例,展示了针对不同平台(Android、iOS及Web)的URL处理方式,以及如何调用navigator.push方法跳转到目标页面。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

weex使用navigator跳转界面

1、url组装,编辑在appUtils.js文件中

exports.getUrl = function (url) {
  let bundleUrl = new String(weex.config.bundleUrl)
  console.log('bundleUrl: ', bundleUrl)
  const isAndroidAssets = bundleUrl.indexOf('file://assets/') >= 0
  const isIOSAssets = bundleUrl.indexOf('file:///') >= 0 && bundleUrl.indexOf('sign-app') > 0
  let nativeBase
  if (isAndroidAssets) {
    nativeBase = 'file://assets/dist/' + url
  } else if (isIOSAssets) {
    nativeBase = bundleUrl.substring(0, bundleUrl.lastIndexOf('/') + 1) + url
  } else {
    let host = 'localhost:8081'
    const matches = /\/\/([^\/]+?)\//.exec(bundleUrl)
    if (matches && matches.length >= 2) {
      host = matches[1]
    }

    if (typeof window === 'object') {
      nativeBase = 'http://' + host + '/'
    } else {
      nativeBase = 'http://' + host + '/'
    }
    nativeBase = nativeBase + url + '.html'
  }
  return nativeBase
}

2、调用navigator跳转到login.vue

	  const navigator = weex.requireModule('navigator')
      let utils = require('./appUtils')
      navigator.push({
        url: utils.getUrl('login'),
        animated: 'true'
      }, event => {
        console.log('callback: ', event)
      })
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值