Skip to content

Template syntax overview

The ElfUI template is declared through defineHtml(...), which will be compiled into a render function that directly operates the DOM during the build period.

ts
export const Counter = defineHtml(`
  <button @click=${inc} :disabled=${disabled}>${count}</button>
`);

Template syntax is divided into two categories:

TypeExample
JavaScript dynamic expressions${count}, :disabled=${disabled}, @click=${inc}
Commandsv-if, v-for, v-model, v-show

TIP

Ordinary dynamic binding uses ${...} first:

ts
defineHtml(`<button @click=${submit} :disabled=${loading}>提交</button>`);

TIP

Scenarios that require template local variables use string expressions, such as v-for:

html
<li v-for="item in list" :key="item.id">{{ item.name }}</li>

Compilation result

WARNING

Templates do not become VNodes. The compiler will split dynamic text, properties, events and control flow into independent bindings, and only update the corresponding DOM points when the state changes.