浏览代码

feat(elevator): add change event

suzigang 3 年之前
父节点
当前提交
4ae7c7320c

+ 1 - 0
src/packages/__VUE/elevator/doc.en-US.md

@@ -481,6 +481,7 @@ app.use(Elevator);
 |-------|----------|-------------|
 |-------|----------|-------------|
 | click-item | Click content | key: string, item: { id: 0, name: '' } |
 | click-item | Click content | key: string, item: { id: 0, name: '' } |
 | click-index | Click index | key: string |
 | click-index | Click index | key: string |
+| change | Change index | index: number |
 
 
 ### API
 ### API
 
 

+ 1 - 0
src/packages/__VUE/elevator/doc.md

@@ -482,6 +482,7 @@ app.use(Elevator);
 |-------|----------|-------------|
 |-------|----------|-------------|
 | click-item | 点击内容 | key: string, item: { id: 0, name: '' } |
 | click-item | 点击内容 | key: string, item: { id: 0, name: '' } |
 | click-index | 点击索引 | key: string |
 | click-index | 点击索引 | key: string |
+| change | 索引改变 | index: number |
 
 
 ### API
 ### API
 
 

+ 8 - 1
src/packages/__VUE/elevator/index.taro.vue

@@ -97,7 +97,7 @@ export default create({
       default: 35
       default: 35
     }
     }
   },
   },
-  emits: ['click-item', 'click-index'],
+  emits: ['click-item', 'click-index', 'change'],
   setup(props, context) {
   setup(props, context) {
     const spaceHeight = 23;
     const spaceHeight = 23;
     const listview: Ref<HTMLElement> = ref() as Ref<HTMLElement>;
     const listview: Ref<HTMLElement> = ref() as Ref<HTMLElement>;
@@ -250,6 +250,13 @@ export default create({
       }
       }
     );
     );
 
 
+    watch(
+      () => state.currentIndex,
+      (newVal: number) => {
+        context.emit('change', newVal);
+      }
+    );
+
     return {
     return {
       classes,
       classes,
       ...toRefs(state),
       ...toRefs(state),

+ 8 - 1
src/packages/__VUE/elevator/index.vue

@@ -77,7 +77,7 @@ export default create({
       default: 35
       default: 35
     }
     }
   },
   },
-  emits: ['click-item', 'click-index'],
+  emits: ['click-item', 'click-index', 'change'],
   setup(props, context) {
   setup(props, context) {
     const listview: Ref<any> = ref(null);
     const listview: Ref<any> = ref(null);
     const state = reactive({
     const state = reactive({
@@ -227,6 +227,13 @@ export default create({
       }
       }
     );
     );
 
 
+    watch(
+      () => state.currentIndex,
+      (newVal: number) => {
+        context.emit('change', newVal);
+      }
+    );
+
     return {
     return {
       classes,
       classes,
       ...toRefs(state),
       ...toRefs(state),