public class DynamicComponent {
private String title;
private String content;
public DynamicComponent(String title, String content) {
this.title = title;
this.content = content;
}
public String getTitle() {
return title;
}
public String getContent() {
return content;
}
}
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Dynamic UI Component</title>
<script src="node_modules/@webcomponents/webcomponentsjs/webcomponents-bundle.js"></script>
</head>
<body>
<dynamic-component title="My Title" content="My Content"></dynamic-component>
<script>
class DynamicComponent extends HTMLElement {
constructor() {
super();
}
connectedCallback() {
const title = this.getAttribute('title');
const content = this.getAttribute('content');
this.innerHTML = `
<h1>${title}</h1>
<p>${content}</p>
`;
}
}
window.customElements.define('dynamic-component', DynamicComponent);
</script>
</body>
</html>