mpVue:小程序项目中,页面跳转程序封装

目录中main.js中

var tabLinks = [
  '/pages/hospital/index',
  '/pages/patient/index',
  '/pages/consult/index',
  '/pages/center/index'
]
function toNavFun (url) {
  wx.navigateTo({
    url: url
  })
}
var toTabFun = function (url) {
  wx.switchTab({
    url: url
  })
}
// 页面跳转 会根据传入的参数进行判断
Vue.prototype.jump = function (url) {
  console.log('URL::::' + url)
  var qflag = url.indexOf('?')
  if (qflag > -1) {
    var _testUrl = url.substring(0, qflag)
    if (tabLinks.indexOf(_testUrl) > -1) {
      toTabFun(_testUrl)
    } else {
      toNavFun(url)
    }
  } else {
    if (tabLinks.indexOf(url) > -1) {
      toTabFun(url)
    } else {
      toNavFun(url)
    }
  }
}
// 跳转页面
Vue.prototype.toNav = toNavFun
// 跳转 tabBar的某个页面
Vue.prototype.toTab = toTabFun

mpVue:小程序项目中,页面跳转程序封装_第1张图片

你可能感兴趣的:(前端)