Coming from
WebFluent for Vue developers
Vue's single-file components, refs, computed values, slots and `v-model` all have a close match in WebFluent. The difference to hold on to is that WebFluent is a compiler with typed markup: there is no `.value`, no template language beside the script, and every prop, slot and event is checked at build time.
A value that changes
You write
const n = ref(0)
In WebFluent
state n = 0
Changing it
You write
n.value++
In WebFluent
n = n + 1
A value worked out from others
You write
const total = computed(() => sum(items.value))
In WebFluent
derived total = items.sum()
A side effect
You write
watchEffect((onCleanup) => { start(); onCleanup(stop) })
In WebFluent
effect { start() cleanup { stop() } }
A handle on an element
You write
<input ref="box"> … box.value.focus()
In WebFluent
Input(bind: q, ref: box) … box.focus()
A component
You write
a .vue file with <script setup> and <template>
In WebFluent
component Card(_ title: String) { … }
Props
You write
defineProps({ title: String })
In WebFluent
component Card(_ title: String, tone: Tone = .calm)
The default slot
You write
<slot />
In WebFluent
children
A named slot
You write
<slot name="trailing" />
In WebFluent
slot trailing, filled as trailing { … }
A scoped slot
You write
<slot :item="item" />
In WebFluent
slot row(item: Todo), filled as row(todo) { … }
An event
You write
defineEmits(["change"]), emit("change", n)
In WebFluent
event change(value: Number), emit change(n)
v-model
You write
<input v-model="q">
In WebFluent
Input(bind: q, label: "Search")
Shared state
You write
provide/inject, Pinia
In WebFluent
store Cart { … }, read as Cart.items after use Cart
A route
You write
vue-router { path: "/users/:id", component: User }
In WebFluent
page User(path: "/users/:id", id: String) { … }
v-if / v-else
You write
<Panel v-if="open" /><p v-else>…</p>
In WebFluent
if open { Panel } else { Text("…") }
v-show
You write
<Panel v-show="open" />
In WebFluent
show open { Panel }
v-for
You write
<li v-for="i in items" :key="i.id">{{ i.name }}</li>
In WebFluent
for i in items by i.id { Text(i.name) }
Class bindings
You write
:class="{ done: todo.done }"
In WebFluent
class: { "done": todo.done }
Transitions
You write
<Transition name="fade">
In WebFluent
.fadeIn, exit: .fadeOut
Fetching
You write
<Suspense> with an async setup, or VueUse's useFetch("/api/users")
In WebFluent
resource users: [User] = http.get("/api/users"), read with match users { … }
A test
You write
Vitest with Vue Test Utils: mount, trigger("click"), text()
In WebFluent
test "…" { click "Save" expect "Saved" }
Things that work differently
One file, one language. A component is declared in .wf with its state, its markup and its handlers together; there is no <template>, no <script> block and no .value to remember. A component's body runs once, and only what reads a changed value updates.
The markup is typed. The compiler knows the props, flags, events and slots of every built-in and of every component you declare. A misspelled prop, an unknown flag (Button("Save").primray) or a handler for an event the component does not fire stops the build, with the fix suggested.
Typed without a second language. There is no lang="ts" and no vue-tsc: a .wf file is typed by the compiler that builds it. The checker infers what it can and asks you to write the rest: a state whose first value says nothing (state items: [Todo] = []), an action that returns (-> Number), a parameter. There is no any: JSON whose shape is open is Json, matched or decoded (User.decode(raw)) before it is read, and no setting turns the checks off.
Pages own their routes. There is no router file. Each page names its path:, and the compiler builds the router from every page.
No imports. Every file under src/ is part of one program, so a component declared anywhere is usable everywhere, and two declarations of one name are an error.
Styles are on the element. A style { } block is CSS for that element, with design tokens ($surface) and nesting (&:hover); there is no <style scoped>, and what a selector over many elements needs goes in a .css file under src/.
Using it inside a Vue app. Publish components as custom elements and use their tags in a template (Publish components as custom elements).
A component, ported
The same counter, in Vue and in WebFluent. It starts at a number the caller passes, counts up on a click, shows a badge when the count is even, and tells the caller about each change.
<script setup>
import { ref, computed } from "vue";
const props = defineProps({ start: { type: Number, default: 0 } });
const emit = defineEmits(["change"]);
const n = ref(props.start);
const even = computed(() => n.value % 2 === 0);
function inc() { n.value++; emit("change", n.value); }
</script>
<template>
<div class="row">
<button @click="inc">+</button>
<span>{{ n }}</span>
<span v-if="even" class="badge">even</span>
</div>
</template>
page Scores(path: "/", title: "Scores", description: "A counter that reports each change.") {
state last = 0
Heading("Scores").h1
Counter(start: 2) { on change(value) { last = value } }
Text("Last change: {last}")
}
component Counter(start: Number = 0) {
event change(value: Number)
state n = start
derived even = n % 2 == 0
Row(gap: .sm, align: .center) {
Button("+") { on click { n = n + 1 emit change(n) } }
Text("{n}")
if even { Badge("even").info }
}
}
- No
.value. A state is read and assigned by its name. derivedreplacescomputed, and knows what it reads.- The event is declared where the component is, and checked where it is handled.