|
|
@ -33,7 +33,39 @@ Vue.use(VueLazyload, { |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|
// 全局挂载公共路由跳转方法
|
|
|
|
Vue.prototype.gotoPath = function(path, options = {}) { |
|
|
|
// 1. 避免重复跳转同一页面
|
|
|
|
const currentPath = this.$router.currentRoute.fullPath |
|
|
|
if (path === currentPath) { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
// 2. 支持两种跳转方式:路径字符串或配置对象
|
|
|
|
if (typeof path === 'string') { |
|
|
|
// 字符串路径,可附带query参数
|
|
|
|
this.$router.push({ |
|
|
|
path, |
|
|
|
query: options.query || {} |
|
|
|
}) |
|
|
|
} else if (typeof path === 'object') { |
|
|
|
// 直接传入路由配置对象(如命名路由)
|
|
|
|
this.$router.push(path) |
|
|
|
} |
|
|
|
|
|
|
|
// 3. 可选的跳转成功回调
|
|
|
|
if (typeof options.success === 'function') { |
|
|
|
options.success() |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
// 4. 错误处理
|
|
|
|
console.error('路由跳转失败:', error) |
|
|
|
if (typeof options.fail === 'function') { |
|
|
|
options.fail(error) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/* eslint-disable no-new */ |
|
|
|
new Vue({ |
|
|
|