layui/example/docs/zh-CN/hooks/useClickOutside.md

43 lines
769 B
Markdown
Raw Normal View History

2021-10-26 18:04:47 +00:00
::: title 基础使用
2021-10-24 16:36:19 +00:00
:::
::: block 使 用 useClickOutside 监 听 元 素 外 click 事 件
:::
2021-10-24 16:36:19 +00:00
```vue
2021-10-26 18:04:47 +00:00
<template>
<lay-button type="primary" ref="buttonRef">当前元素</lay-button>
2021-10-26 18:04:47 +00:00
</template>
2021-10-24 16:36:19 +00:00
2021-10-26 18:04:47 +00:00
<script>
import { ref, watch } from 'vue'
2021-12-06 01:35:18 +00:00
import { useClickOutside } from '@layui/hooks-vue'
2021-10-26 18:04:47 +00:00
export default {
setup() {
const buttonRef = (ref < null) | (HTMLElement > null)
const isClickOutside = useClickOutside(buttonRef)
watch(isClickOutside, () => {
console.log('元素外 click 事件')
2021-10-26 18:04:47 +00:00
})
return {
buttonRef,
2021-10-26 18:04:47 +00:00
}
},
2021-10-26 18:04:47 +00:00
}
</script>
```
2021-10-26 18:04:47 +00:00
::: title 使用备注
2021-10-26 18:04:47 +00:00
:::
2021-11-07 07:55:08 +00:00
::: table
| 备注 | 描述 | 类型 |
| -------------- | --------------- | ---- |
| isClickOutside | 使用 watch 监听 | Ref |
2021-11-07 07:55:08 +00:00
2021-11-07 07:56:24 +00:00
:::