学习应用一下不常用的element-plus抛出的指令

学习应用一下element-plus抛出的指令

click-outside

效果图

作用

这个指令的主要目的是监听页面上的点击事件,并判断点击是否发生在指定元素之外。如果是,那么执行一些操作,如关闭弹出窗口

使用
js 复制代码
<template>
  <div
    v-click-outside="() => toggele('', false)"
    v-if="show"
    :class="['absolute']"
    :key="path.x + path.y"
    :style="{ left: path.x + 'px', top: path.y + 'px' }"
  >
    <el-card class="relative z-10">
      <template #header>
        <div class="card-header">
          <span>操作菜单栏</span>
        </div>
      </template>
      <div class="text item" @click="closeAll">关闭所有</div>
      <div class="text item" @click="closeOther">关闭其他</div>
    </el-card>
  </div>
</template>

<script setup lang="ts">
import { useGlobalStore } from "@/store/index"
import { ClickOutside as vClickOutside } from "element-plus"

const store = useGlobalStore()
const show = ref(false)
const index = ref("")
defineProps({
  path: {
    type: Object,
    default: () => {
      return {
        x: 0,
        y: 0
      }
    }
  }
})
const closeAll = () => {
  console.log("关闭所有")
  store.clearTab()
  toggele("", false)
}
const closeOther = () => {
  console.log("关闭其他")
  store.closeOtherTab(index.value)
  toggele("", false)
}

const toggele = (key: string, visible = true) => {
  if (key) {
    index.value = key
  }
  show.value = visible
  console.log(show.value)
}

defineExpose({
  toggele
})
</script>

<style>
.mouseWheel {
  height: 500px;
  overflow-y: scroll;
}
</style>

mousewheel

效果图
作用

允许直接在模板中绑定滚轮事件的处理函数,而无需手动添加事件监听器,从而简化了鼠标滚轮事件处理的复杂度。

使用
js 复制代码
<template>
  <div v-mousewheel="handleScroll" class="my-container">
    <!-- 这里可以是任何你希望在滚轮滚动时互动的内容,比如一个列表或图片等 -->
    <div class="h-[200px]" v-for="(item, index) in 10" :key="index">{{ item }}</div>
  </div>
</template>

<script setup lang="ts">
import { Mousewheel as vMousewheel } from "element-plus"

const handleScroll = (event: WheelEvent) => {
  console.log("滚动了", event)
}
</script>
<style>
.my-container {
  height: 600px;
  overflow-y: scroll;
}
</style>

repeat-click

效果图
作用

这个指令可以帮助开发者在用户进行连续快速点击操作时触发特定的函数或动作,比如长按加减等

使用
js 复制代码
<template>
  <el-button v-repeat-click="{ handler: handleRepeatClick, interval: 1000, delay: 500 }">连续点击我</el-button>
</template>

<script setup>
import { vRepeatClick } from "element-plus"

let count = 0

function handleRepeatClick() {
  count++
  console.log("按钮被点击了", count)
}
</script>
相关推荐
八目蛛32 分钟前
色盲测试小游戏
vue.js·vue3·html5
雪碧聊技术8 小时前
前端项目代码发生改变,如何重新部署到linux服务器?
前端·vue3·centos7·代码更新,重新部署
liulilittle8 小时前
C++ 浮点数封装。
linux·服务器·开发语言·前端·网络·数据库·c++
wordbaby8 小时前
Expo 进阶指南:赋予 TanStack Query “原生感知力” —— 深度解析 AppState 与 NetInfo
前端·react native
Moment9 小时前
从美团全栈化看 AI 冲击:前端转全栈,是自救还是必然 🤔🤔🤔
前端·后端·面试
天问一9 小时前
使用 Vue Router 进行路由定制和调用的示例
前端·javascript·vue.js
源码获取_wx:Fegn089510 小时前
基于springboot + vue心理健康管理系统
vue.js·spring boot·后端
韩立学长10 小时前
【开题答辩实录分享】以《基于Vue的非遗文化知识分享平台的设计与实现》为例进行选题答辩实录分享
前端·javascript·vue.js
优弧10 小时前
离开舒适区100天,我后悔了吗?
前端·后端·面试
胡gh10 小时前
css的臂膀,前端动效的利器,还是布局的“隐形陷阱”?
前端·css·html