[Vuejs]-How to use better scroll the element when the parameter is a letter

0👍

I think there is a time when watch function run, this.$refs[this.letter] is not available yet. So you might want to check:

watch: {
  letter () {
    if (this.letter && this.$refs[this.letter]) {
      const element = this.$refs[this.letter][0]
      this.scroll.scrollToElement(element)
    }
  }
}

Your cities has different ref, you don’t need to access [0] element

   watch: {
      letter () {
        if (this.letter && this.$refs[this.letter]) {
          const element = this.$refs[this.letter]
          this.scroll.scrollToElement(element)
        }
      }
    }

Leave a comment