Browse Source

fix(tab): 点击事件报错处理 (#664)

* fix: tab组件兼容taro

* fix: 完善tab文档和样式

* fix: 兼容小程序

* fix: 修改tab监听事件

* fix: 优化tab点击事件

Co-authored-by: richard1015 <51844712@qq.com>
zhenyulei 4 years ago
parent
commit
4224846470
2 changed files with 15 additions and 10 deletions
  1. 7 4
      src/packages/__VUE/tab/index.taro.vue
  2. 8 6
      src/packages/__VUE/tab/index.vue

+ 7 - 4
src/packages/__VUE/tab/index.taro.vue

@@ -196,10 +196,13 @@ export default create({
       for (let i = 0; i < 100; i++) arrnew.push(i);
       arr.value = arrnew;
     });
-    watchEffect(
-      () => (ctx.slots.default ? ctx.slots.default() : ''),
-      () => {
-        initTitle();
+    watch(
+      () => ctx.slots.default(),
+      (val, oldVal) => {
+        if (val) {
+          ctx.slots.default();
+          initTitle();
+        }
       }
     );
     watchEffect(() => {

+ 8 - 6
src/packages/__VUE/tab/index.vue

@@ -140,7 +140,6 @@ export default create({
       nutuiSwiper.value.to(index);
     }
     function initTitle() {
-      console.log(11);
       titles.length = 0;
       if (ctx.slots.default) {
         const slots: VNode[] =
@@ -166,10 +165,13 @@ export default create({
     onMounted(() => {
       initTitle();
     });
-    watchEffect(
-      () => (ctx.slots.default ? ctx.slots.default() : ''),
-      () => {
-        initTitle();
+    watch(
+      () => ctx.slots.default(),
+      (val, oldVal) => {
+        if (val) {
+          ctx.slots.default();
+          initTitle();
+        }
       }
     );
     watchEffect(() => {
@@ -178,7 +180,7 @@ export default create({
     watch(
       () => activeIndex.value,
       (val, oldVal) => {
-        ictx.emit('switch-tab', activeIndex.value);
+        ctx.emit('switch-tab', activeIndex.value);
       }
     );
     return {