Skip to content

Commit 93c1afb

Browse files
committed
postlist,添加对鼠标中键点击的默认行为阻止,修复鼠标中间导致打开2个tab的问题
1 parent 1828e01 commit 93c1afb

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

blog/components/PostList.vue

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
}"
1313
@click="(e) => goPostDetail(e, item)"
1414
@click.middle="(e) => goPostDetail(e, item, true)"
15+
@mousedown="preventDefaultMiddleClick"
1516
>
1617
<!-- seo 为了抓取链接 -->
1718
<NuxtLink
@@ -111,6 +112,7 @@
111112
<template v-if="item.type === 1">
112113
<NuxtLink
113114
@click.stop
115+
@click.middle.stop
114116
:to="{
115117
name: 'postDetail',
116118
params: { id: item.alias || item._id },
@@ -132,6 +134,7 @@
132134
<NuxtLink
133135
class="dflex flexCenter cGray94 hover:text-primary-500"
134136
@click.stop
137+
@click.middle.stop
135138
:to="{
136139
name: 'postDetail',
137140
params: { id: item.alias || item._id },
@@ -146,6 +149,7 @@
146149
<NuxtLink
147150
class="dflex flexCenter cGray94 hover:text-primary-500"
148151
@click.stop
152+
@click.middle.stop
149153
:to="{
150154
name: 'postDetail',
151155
params: { id: item.alias || item._id },
@@ -166,6 +170,7 @@
166170
class="dflex flexCenter cursor-pointer hover:text-primary-500"
167171
:class="item.isLike ? 'text-primary-500' : 'cGray94'"
168172
@click.stop="likePost(item._id)"
173+
@click.middle.stop
169174
v-if="likeListInited"
170175
>
171176
<!-- 加载 -->
@@ -466,16 +471,15 @@ const goPostDetail = (e, item, middle) => {
466471
// 判断是否按着ctrl键,如果是就在新标签页打开
467472
// 如果middle为true,就在新标签页打开
468473
if (middle || e.ctrlKey || e.metaKey) {
469-
if (middle) {
470-
e.preventDefault()
471-
}
474+
console.log('middle')
472475
// resolveUrl
473476
const url = router.resolve({
474477
name: routeName,
475478
params: { id },
476479
}).href
477480
window.open(url, '_blank')
478481
} else {
482+
console.log('post push')
479483
router.push({
480484
name: routeName,
481485
params: {
@@ -485,6 +489,14 @@ const goPostDetail = (e, item, middle) => {
485489
}
486490
}
487491
492+
const preventDefaultMiddleClick = (e) => {
493+
console.log(e.button, e.target.tagName)
494+
if (e.button === 1 && e.target.tagName !== 'A') {
495+
console.log('preventDefault middle click')
496+
e.preventDefault()
497+
}
498+
}
499+
488500
// console.log(postsData)
489501
const likeListInited = ref(false)
490502
const likeListLoading = ref(false)

0 commit comments

Comments
 (0)