
Enter a search term above to see results...
Enter a search term above to see results...
While inline templates and styles work well for small components, larger ones benefit from separate files. This lesson shows how to organize your component code across multiple files for better maintainability.
A typical component consists of three files:
component.js
- Component definition and logiccomponent.html
- HTML templatecomponent.css
- Component stylesThis separation makes your code more maintainable and allows for better tooling support.
The getText
function loads external files at build time as shown in component.js. Although in practice with a build tool like Vite you can import the files directly using import
statements.
defineComponent
and getText
await getText('./filename')
The component.html file contains our markup with expressions:
{user.name}
src="{user.avatar}"
In component.css, we define styles that are scoped to our component:
.profile
, .name
) without needing prefixes.var(--standard-5)
enable themingExtend the user profile to include additional information like email and location.
Hint:
defaultState