getting on with petite vue <-> Hugo shortcodes

This commit is contained in:
Helmut Merz 2023-02-19 12:39:20 +01:00
parent dd3f97bbab
commit ad1c48b7ed
3 changed files with 25 additions and 15 deletions

View file

@ -3,20 +3,16 @@ import { createApp } from './lib/petite-vue.es.js'
createApp({
$delimiters: ['{|', '|}'],
urlParams: new URL(location.href).searchParams,
save
mydata: Data(),
}).mount()
function save(text: string) {
console.log(text)
}
const s: string = 'test-string'
save(s)
for (let i = 0; i < 10; i++) {
setTimeout(function () {
console.log(i);
}, 100 * i);
function Data() {
return {
data: '',
save(txt: string) {
this.data += '\n' + txt
}
}
}
// p = new URL(location.href).searchParams

View file

@ -0,0 +1,11 @@
<div v-scope>
<input type="text" name="txt"
@change="mydata.save($el.value)" />
</div>
<div v-scope>
<pre>id = {| urlParams.get('id') |}</pre>
<pre v-effect="$el.textContent = mydata.data" ></pre>
</div>

View file

@ -1,4 +1,7 @@
<div v-scope="{ count: 0 }">
{| count |}
<button @click="count++">inc</button>
{{- $initval := default 0 (.Get "init") -}}
{{- $expr := .Get "expr" | default "count++" -}}
{{- $label := or (.Get "label") "inc" -}}
<div v-scope="{ count: {{ $initval }} }">
{| count |}
<button @click="{{ $expr }}">{{ $label }}</button>
</div>