M
M
Maxim2019-12-09 12:05:46
Vue.js
Maxim, 2019-12-09 12:05:46

How to make an anchor in vue if the block is loaded after?

the task is to make a link when clicking on which the transition was to the desired comment www.url.url#/tickets/single/1302#comment_3257
how to make a simple anchor, I know, but so that it works after the comments are loaded?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lumore, 2019-12-09
@xiiicool

export default {
  data: () => ({
    comments: [],
  }),

  methods: {
    loadComments() {
      this.comments = axios.get('...').then(response => response.data)
    },

   scrollToComment() {}
  },

  async mounted() {
    await this.loadComments();
    const commentId = this.$router.query.comment

    // scrollToComment - ваша функция, которая скроллит до коммента
    this.$nextTick(this.scrollToComment(commentId))
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question