Super Sale Limited Time 50% OFF for All-Access Plans
Save 50% Now

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
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • 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
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(