判断对象/数组是否为空

// this.$route.params 判断路由接收的参数是否为空对象

    if (Object.keys(this.$route.params).length !== 0) {
      this.currentX = this.$route.params.idx;
    } else {
      this.currentX = 0;
    }
  },

判断数组
  if ( (this.$route.params).length !== 0) {
      this.currentX = this.$route.params.idx;
    } else {
      this.currentX = 0;
    }
  },

猜你喜欢

转载自blog.csdn.net/Tom__cy/article/details/106071585