فهرست منبع

固钉:组件优化

洪海涛 4 سال پیش
والد
کامیت
3d0f50eeb3
1فایلهای تغییر یافته به همراه19 افزوده شده و 4 حذف شده
  1. 19 4
      src/components/affix/affix.vue

+ 19 - 4
src/components/affix/affix.vue

@@ -1,6 +1,6 @@
 <template>
-  <div ref="placeholderNode" :style="{ ...placeholderNodeStyle }">
-    <div ref="fixedNode" :style="{ ...fixedNodeStyle }">
+  <div ref='placeholderNode' :style='{ ...placeholderNodeStyle }'>
+    <div ref='fixedNode' :style='{ ...fixedNodeStyle }'>
       <slot />
     </div>
   </div>
@@ -46,10 +46,23 @@ export default {
       type: String,
       required: false,
       default: () => null
+    },
+    /* 用户自定义函数*/
+    userFun: {
+      type: Function,
+      required: false,
+      default: () => {
+      }
+    },
+    /* 定义节流函数执行间隔时间 */
+    listenTime: {
+      type: Number,
+      required: false,
+      default: () => 300
     }
   },
   data() {
-    this.lazyUpdatePosition = _.throttle(this.lazyUpdatePosition, 300)
+    this.lazyUpdatePosition = _.throttle(this.lazyUpdatePosition, this.listenTime)
     return {
       placeholderNodeStyle: '',
       fixedNodeStyle: '',
@@ -81,6 +94,7 @@ export default {
           eventName,
           () => {
             this.lazyUpdatePosition()
+            this.userFun()
           }
         )
       })
@@ -125,6 +139,7 @@ export default {
         width: placeholderReact.offsetWidth + 'px',
         height: placeholderReact.offsetHeight + 'px'
       }
+
     },
     unInit() {
       const { entity } = this
@@ -145,4 +160,4 @@ export default {
 }
 </script>
 
-<style scoped lang="less"></style>
+<style scoped lang='less'></style>