Browse Source

提交

master
chenkainan 2 months ago
parent
commit
5defc890ed
  1. 1
      src/components/layout/HeaderNav.vue
  2. 8
      src/components/layout/HomeLayout.vue
  3. 3
      src/libs/utils.js
  4. 32
      src/main.js
  5. 36
      src/router/index.js

1
src/components/layout/HeaderNav.vue

@ -22,7 +22,6 @@
></a ></a
> >
<a href="/User/OrderList" v-if="isLogin">我的订单</a> <a href="/User/OrderList" v-if="isLogin">我的订单</a>
<a href="">商户后台</a>
<a href="javascript:;" @click="handleLogout" v-if="isLogin">退出</a> <a href="javascript:;" @click="handleLogout" v-if="isLogin">退出</a>
</div> </div>
</div> </div>

8
src/components/layout/HomeLayout.vue

@ -30,8 +30,12 @@
</div> </div>
<div class="btn-group"> <div class="btn-group">
<el-button type="danger" size="mini">登录</el-button> <el-button type="danger" size="mini" @click="gotoPath('/Login')"
<el-button type="warning" size="mini">注册</el-button> >登录</el-button
>
<el-button type="warning" size="mini" @click="gotoPath('/Register')"
>注册</el-button
>
<el-button type="primary" size="mini">客服</el-button> <el-button type="primary" size="mini">客服</el-button>
</div> </div>

3
src/libs/utils.js

@ -62,9 +62,6 @@ export default {
} else { } else {
return 'https://static.ticket.sz-trip.com' + img; return 'https://static.ticket.sz-trip.com' + img;
} }
},
gotoPath(path) {
this.$router.push(path)
} }
} }
} }

32
src/main.js

@ -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 */ /* eslint-disable no-new */
new Vue({ new Vue({

36
src/router/index.js

@ -16,6 +16,24 @@ const router = new Router({
}, },
component: () => import('@/views/Index.vue') component: () => import('@/views/Index.vue')
}, },
{
path: '/Login',
name: 'Login',
meta: {
title: '登录 - 精品商城',
keepAlive: false
},
component: () => import('@/views/Login.vue')
},
{
path: '/Register',
name: 'Register',
meta: {
title: '注册 - 精品商城',
keepAlive: false
},
component: () => import('@/views/Register.vue')
},
{ {
path: '/Home', path: '/Home',
name: 'Home', name: 'Home',
@ -209,24 +227,6 @@ const router = new Router({
// }, // },
// component: () => import('@/views/OrderDetail.vue') // component: () => import('@/views/OrderDetail.vue')
// }, // },
{
path: '/Login',
name: 'Login',
meta: {
title: '登录 - 精品商城',
keepAlive: false
},
component: () => import('@/views/Login.vue')
},
{
path: '/Register',
name: 'Register',
meta: {
title: '注册 - 精品商城',
keepAlive: false
},
component: () => import('@/views/Register.vue')
},
// { // {
// path: '*', // path: '*',
// name: 'NotFound', // name: 'NotFound',

Loading…
Cancel
Save