Introducing ReUI:Open-source UI components and apps built with React, Next.js and Tailwind CSS
Browse ReUI

Sticky component problem


Hi,
I'm using the Tailwind version of Metronic with Vue 3 and Nuxt 3. The sticky component works fine when the page initially loads, but after navigating to a different route, the sticky elements don't function correctly. I tried updating them, but it didn't work.


import KTComponent, { KTSticky } from "./assets/metronic/core/index"
import KTLayout from "./assets/metronic/app/layouts/demo1"

const route = useRoute()

watch(() => route.path, () => {
nextTick(() => {
KTComponent.init()
KTLayout.init()
setTimeout(() => {
const components = document.querySelectorAll("[data-sticky="true"]")
components.forEach((element) => {
const sticky = KTSticky.getOrCreateInstance(element)
sticky.update()
})
}, 100)
})
})


And scrollspy elements don't function correctly neither.


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (2)


It sounds like the sticky component needs to be re-initialized after route changes. Try using Vue's nextTick() or a watcher to manually trigger the update when navigating between routes.
seriesdonghua.org



Hi,

Thank you for reaching out to us.

Unfortunately, at the moment, we haven't tried combining Metronic with Nuxt 3, we will check it and consider implementing Nuxt in the next releases.
To fix this problem please make sure to call Metronic initialization functions after your content is mounted and call initialization on every page separately.

You can checkout our Next.js integration guide, and implement the initialization the same way for your Nuxt project.
https://keenthemes.com/metronic/tailwind/docs/getting-started/integration/nextjs

Regards,
Lauris Stepanovs,
Keenthemes Support Team


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(