Help understanding use of JS assets in Lume Components #741
-
Hi, I get that Lume Components are meant for generating static html. CSS behaves as I would expect: it gets merged into Am I misunderstanding how this is supposed to be used? If this isn't how I should use JS Component assets, why provide the mechanism at all? Adding to my confusion is that I need to subsequently include I've tried several times to use components to isolate pieces of UI with styling and some lightweight JS needs, but keep running up against this issue and it seems easier to just write the JS in a 'global' script instead. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Technically, the export const js = `customElements.define("my-button", class extends HTMLElement {})`;
export default function ({ content }) {
return `<my-button>${content}</my-button>`
} But this is not, because the js key contains real js code: export const js = customElements.define("my-button", class extends HTMLElement {});
export default function ({ content }) {
return `<my-button>${content}</my-button>`
} In the incoming Lume 3, it's possible to define the css and js code in different files, so you don't have to use string values inside the main component file and the editor can highlight the code. More info here: https://github.com/lumeland/blog/blob/main/posts/lume-3.md#folder-components |
Beta Was this translation helpful? Give feedback.
Yes, the
js
key of components are meant to output JS code for the browser.