Get 2024 Templates Mega Bundle!14 Bootstrap, Vue & React Templates + 3 Vector Sets
Get for 99$

Create the main menu asynchronously using the ApiService


Hello!

I'm using Metronic Vue version 8.1.8.

To manage permissions on the server side, I would like to create the main menu asynchronously by making a request to the server using the ApiService.

I made the following changes in the original Metronic Vue Demo7 component /src/layouts/main-layout/aside/Menu.vue:

Commented out the line that imports MainMenuConfig.

// import MainMenuConfig from "@/core/config/MainMenuConfig";


Created a constant to replace MainMenuConfig.

const MainMenuConfig = ref<Array<any>>([]);


Added the ApiService request to the onMounted hook and assigned the obtained result to MainMenuConfig.value (the result obtained from the request is exactly the same as the definition in MainMenuConfig file @/core/config/MainMenuConfig.ts):

onMounted(async () => {
if (scrollElRef.value) {
scrollElRef.value.scrollTop = 0;
}

ApiService.setHeader();
await ApiService.get("/api/menu")
.then(({ data }) => {
MainMenuConfig.value = data
})
});


Unfortunately, I did not succeed.

Could you please assist me with this issue?


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


Hi Fernando,

Please make sure your request passes successfully and data is received.
If you are following the same object structure as in the default Metronic theme then your code should be working.

Could you please check your browser's console for errors?

Regards,
Lauris Stepanovs,
Keenthemes Support Team



Hi Lauris,

Sorry, I found a difference in the result coming from the server.

It worked. Thank you.



Hi Fernando,

Glad to hear that. Please don't hesitate to reach out if you need anything more from us.

Regards,
Lauris Stepanovs,
Keenthemes Support Team


Your Support Matters!

We will highly appreciate your Metronic Review on Themeforest.
Please go to Themeforest Downloads page, select Metronic & leave your feedback.
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  :(