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

Vue router and js file


Hello! I set up a project from scratch on laravel + Vue, and started needing html pages migrated. The ”/assets/js/scripts.bundle.js” is not working in the components which are connected via <router-view>. Can you please tell me what this problem could be due to ?


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


Here is my main blade http://joxi.ru/12M055lt809dwm , this is App.vue http://joxi.ru/v29KGGoTjzJK9r . The components that through router-view don't work scripts. The Navigation and Sidebar components work fine. I use html -> demo1. No errors in the console



Hi Grigor,

Could you please specify the followings?

  • Which Metronic version and demo are you using?
  • Which build tool? Webpack/Gulp
  • Do you have any errors in your console?



Regards,
Lauris Stepanovs,
Keenthemes Support Team

Here is my main blade http://joxi.ru/12M055lt809dwm , this is App.vue http://joxi.ru/v29KGGoTjzJK9r . The components that through router-view don't work scripts. The Navigation and Sidebar components work fine. I use html -> demo1. No errors in the console



Hi,

By default, we are initializing all scripts on the first-page load. The router-view content is mounted asynchronously, so components used inside a page will not be initialized.

To fix this issue you can move our script initialization code from the page load event to the component mounted function, also you will need to do the same initialization on every route change to initialize page content items.

You can find component initialization file examples in our Metronic Vue version src/core/plugins/keenthemes.ts.

Regards,
Lauris Stepanovs,
Keenthemes Support Team



Hello!
I don't quite understand how to plug the scripts into a component and re-initialise them each time the rota is changed,
Could you please show on my example how to implement this, as I have not worked with type script.



Hi,

Our main components are initialized in file src/js/components/_init.js, using the code below, which will be triggered only when you refresh a page.

// On document ready
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", function() {
KTComponents.init();
});
} else {
KTComponents.init();
}


Theme main components are initialized using function KTComponents.init();, this is how you can trigger initialization.

If you are using gulp to bundle assets then you should have KTComponents global instance and in your Vue component mounted function you can just call the init function of KTComponents.


onMounted(() => {
nextTick(() => {
KTComponents.init();
});
})


You can do the same every time the router is changed.

router.beforeEach((to, from, next) => {
KTComponents.init();
});



Regards,
Lauris Stepanovs,
Keenthemes Support Team



the problem and the question is that I just use html http://joxi.ru/RmzlooNHVRkdDA , I move the needed html into a clean project in laravel + vue as needed



Hi Grigor,

As I mentioned above, in our HTML version, we are making initialization in the page load event and scripts get initialized for every page separately.

You are using a Vue router so most likely your application is a single-page application and the page is loaded only once it is the reason why our initialization solution from HTML version isn't compatible with SPA. To use our scripts you need to add additional vue logic to handle script initialization, check my previous comment.

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