v-for="(tag, index) in $store.getters.tagsViewList"
:key="tag.fullPath"
:to="{ path: tag.fullPath }"
@contextmenu.prevent="openMenu($event, index)"
>
{{ tag.title }}
<svg-icon
v-show="!isActive(tag)"
icon="close"
@click.prevent.stop="onCloseClick(index)"
></svg-icon>
</router-link>
</el-scrollbar>
<context-menu
v-show="visible"
:style="menuStyle"
:index="selectIndex"
></context-menu>
</div>
</template>
<script setup>
import ContextMenu from './ContextMenu.vue'
import { ref, reactive, watch } from 'vue'
import { useRoute } from 'vue-router'
...
// contextMenu 相关
const selectIndex = ref(0)
const visible = ref(false)
const menuStyle = reactive({
left: 0,
top: 0
})
/**
* 展示 menu
*/
const openMenu = (e, index) => {
const { x, y } = e // 事件对象中,得到鼠标点击的位置
// 作为行内样式绑定
menuStyle.left = x + 'px'
menuStyle.top = y + 'px'
// 点击项
selectIndex.value = index
visible.value = true
}
</script>
复制代码
contextMenu 变乱处理
对于 contextMenu 的变乱一共分为三个:
革新
关闭右侧
关闭所有
革新 =>
router.go(n) 是 Vue Router 提供的一个方法,它可以在欣赏器的历史纪录中进步或后退 n 步。 当 n 为正数时,router.go(n) 会进步 n 步;当 n 为负数时,会后退 n 步;当 n 为 0 时,它会重新加载当前的页面。在 如下 中,router.go(0) 相当于革新当前页面。
const router = useRouter()
const onRefreshClick = () => {
router.go(0)
}
复制代码
在 store 中,创建删除 tags 的 mutations,该 mutations 需要同时具备以下三个能力: