新建 navTo.js 文件
const togo = function(url,data){
url += (url.indexOf('?') < 0 ? '?' : '&') + param(data)
uni.navigateTo({
url
})
}
export function param(data) {
let url = ''
for (var k in data) {
let value = data[k] !== undefined ? data[k] : ''
url += '&' + k + '=' + encodeURIComponent(value)
}
return url ? url.substring(1) : ''
}
export {togo}
挂载全局到 main.js
import * as navTo from '@/utils/navTo'
Vue.prototype.$navTo = navTo
组件内使用
handleEditShift (params){
let url = '/pages/template/stage/xxx/xxx/index.vue'
let param = params
this.$navTo.togo(url,param)
}
接收值
onLoad(option) {
console.log(option, 'option')
},