Skip to content

Commit

Permalink
Added the vue3-sfc-loader to ActionMenuItem
Browse files Browse the repository at this point in the history
  • Loading branch information
HeriLFIU committed Dec 13, 2024
1 parent add1c9c commit d0b9dde
Showing 1 changed file with 56 additions and 3 deletions.
59 changes: 56 additions & 3 deletions src/components/kytos/napp/ActionMenuItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,60 @@

<script>
import Vue from 'vue'
import httpVueLoader from "./httpVueLoader.js"
import { loadModule } from "vue3-sfc-loader"
const options = {
moduleCache: {
vue: Vue
},
pathResolve({ refPath, relPath }, options) {
if (relPath === '.')
return refPath;
if (relPath[0] !== '.' && relPath[0] !== '/')
return relPath;
return String(new URL(relPath, refPath === undefined ? window.location : refPath));
},
handleModule: async function (type, getContentData, path, options) {
switch (type) {
case '.css':
options.addStyle(await getContentData(false));
return null;
case '.kytos':
console.log("Kytos detected");
return null;
default: return undefined; // let vue3-sfc-loader handle this
}
},
async getFile(url) {
const res = await fetch(url);
if (!res.ok)
throw Object.assign(new Error(url + ' ' + res.statusText), { res });
return await res.text();
},
addStyle(textContent) {
const style = Object.assign(document.createElement('style'), { textContent });
const ref = document.head.getElementsByTagName('style')[0] || null;
document.head.insertBefore(style, ref);
},
log(type, ...args) {
console.log("vue3-sfc-loader log:");
console[type](...args);
}
}
export default {
name: 'k-action-menu-item',
Expand Down Expand Up @@ -36,8 +89,8 @@ export default {
$.each(self.components, function(index, component){
if('url' in component){
// random is needed to avoid cache of components.
var url = self.$kytos_server+component.url+"?random="+Math.random()
Vue.component(component.name, httpVueLoader(url))
var url = self.$kytos_server+component.url
self.$kytos.component(component.name, Vue.defineAsyncComponent( () => loadModule(url, options) ))
}
})
},
Expand Down

0 comments on commit d0b9dde

Please sign in to comment.