Showing
2 changed files
with
20 additions
and
4 deletions
| 1 | /* | 1 | /* |
| 2 | * @Date: 2022-07-26 09:49:54 | 2 | * @Date: 2022-07-26 09:49:54 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2024-10-11 11:29:08 | 4 | + * @LastEditTime: 2024-10-12 11:51:56 |
| 5 | * @FilePath: /hager/src/common/mixin.js | 5 | * @FilePath: /hager/src/common/mixin.js |
| 6 | * @Description: 文件描述 | 6 | * @Description: 文件描述 |
| 7 | */ | 7 | */ |
| ... | @@ -43,5 +43,21 @@ export default { | ... | @@ -43,5 +43,21 @@ export default { |
| 43 | } | 43 | } |
| 44 | }, | 44 | }, |
| 45 | }, | 45 | }, |
| 46 | + directives: { | ||
| 47 | + clickOutside: { | ||
| 48 | + bind(el, binding) { | ||
| 49 | + el.clickOutsideEvent = function(event) { | ||
| 50 | + // 检测点击是否在指定元素外部 | ||
| 51 | + if (!(el === event.target || el.contains(event.target))) { | ||
| 52 | + binding.value(); // 触发绑定的方法 | ||
| 53 | + } | ||
| 54 | + }; | ||
| 55 | + document.addEventListener('click', el.clickOutsideEvent); | ||
| 56 | + }, | ||
| 57 | + unbind(el) { | ||
| 58 | + document.removeEventListener('click', el.clickOutsideEvent); | ||
| 59 | + } | ||
| 60 | + } | ||
| 61 | + }, | ||
| 46 | }, | 62 | }, |
| 47 | }; | 63 | }; | ... | ... |
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2024-09-26 13:42:11 | 2 | * @Date: 2024-09-26 13:42:11 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2024-10-10 13:55:13 | 4 | + * @LastEditTime: 2024-10-12 11:52:42 |
| 5 | * @FilePath: /hager/src/components/common/hagerHeader.vue | 5 | * @FilePath: /hager/src/components/common/hagerHeader.vue |
| 6 | * @Description: 文件描述 | 6 | * @Description: 文件描述 |
| 7 | --> | 7 | --> |
| ... | @@ -49,7 +49,7 @@ | ... | @@ -49,7 +49,7 @@ |
| 49 | </el-col> | 49 | </el-col> |
| 50 | </el-row> | 50 | </el-row> |
| 51 | <el-collapse-transition> | 51 | <el-collapse-transition> |
| 52 | - <div v-show="show" class="product-center"> | 52 | + <div v-show="show" class="product-center" v-click-outside="closeMenu"> |
| 53 | <div style="display: flex; width: 100%;"> | 53 | <div style="display: flex; width: 100%;"> |
| 54 | <div class="product-left-wrapper"> | 54 | <div class="product-left-wrapper"> |
| 55 | <div :class="['product-left-item', p_index === index ? 'active' : '']" v-for="(item, index) in product_menu" :key="index" @click="onClick(item, index)"> | 55 | <div :class="['product-left-item', p_index === index ? 'active' : '']" v-for="(item, index) in product_menu" :key="index" @click="onClick(item, index)"> |
| ... | @@ -361,7 +361,7 @@ export default { | ... | @@ -361,7 +361,7 @@ export default { |
| 361 | closeMiniMenu () { | 361 | closeMiniMenu () { |
| 362 | this.show_menu = false; | 362 | this.show_menu = false; |
| 363 | $('body').css('overflow', 'auto'); | 363 | $('body').css('overflow', 'auto'); |
| 364 | - } | 364 | + }, |
| 365 | } | 365 | } |
| 366 | } | 366 | } |
| 367 | </script> | 367 | </script> | ... | ... |
-
Please register or login to post a comment