T
T
tenaro2021-03-14 10:06:23
Vue.js
tenaro, 2021-03-14 10:06:23

vue.js. links with href="#anchor", how to make them work?

Project on vue-cli2, connected vue-router

links come in the content from the server, upon request, for example a href="#block1"...
when you click on them, instead of scrolling to the desired block, the page is reloaded

- how to make the standard ones work anchors in normal links?
- how to form a router-link from ordinary links so that there is no page reload on click?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
tenaro, 2021-03-14
@tenaro

the simplest solution I found is to hang @click on the container into which the content is loaded by Ajax,
in this function, native js look at e.target, determine that this is a link, its hash, and twist to the desired block

I
Ivan, 2021-03-15
@frankieksai

const el = this.$el.getElementsByClassName("block1")[0];
        if (el) {
          el.scrollIntoView({ behavior: "smooth", alignToTop: true });
        }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question