Get 2024 Templates Mega Bundle!$1000 worth of 19 Bootstrap HTML, Vue & React Templates + 3 Vector Sets for just $9
Get for 99$

How to access KTLayout functionality inside Vue component?


I've recently implemented Metronic in my Vue app. I've setup demo1 and I can see it has some interesting functions in demo1.js, like _isSidebarCollapse()

What would be the best way to access these throughout my app?


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 (4)


Hi,

May I know which Metronic version are you using? Is it Metronic 9 Tailwind ?
In this case, you can call the global method KTLayout.isSidebarCollapse() to get the sidebar status.

Regards.



Ya, I'm using Metronic 9 Tailwind, but when I run that method on a component I get an error: KTLayout is not defined

Here is an example of what I'm doing:

<template>
<div></div>
</template>

<script setup>
console.log(KTLayout.isSidebarCollapse())
</script>



Hi,

Noted, our Vue expert will check it further and get back to you with a solution shortly.

Regards.



Hi,

You can import KTLayout and use isSidebarCollapse() function inside onMounted as shown below.


<script lang="ts" setup>
import { nextTick, onMounted } from "vue";
import KTLayout from "./metronic/app/layouts/demo1.js";

onMounted(() => {
nextTick(() => {
console.log(KTLayout.isSidebarCollapse());
});
});
</script>


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  :(