Public
HTTP (deprecated)
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { html, htmlResponse } from "https://esm.town/v/postpostscript/html";
import { Layout } from "https://esm.town/v/postpostscript/htmlComponentLibrary";
import { getValNameFromUrl } from "https://esm.town/v/postpostscript/meta";
import { Ribbon } from "https://esm.town/v/postpostscript/Ribbon";
import { vueSfc, vueSfcInline } from "https://esm.town/v/postpostscript/vue";
export const CounterSetup = vueSfc(
"CounterSetup",
`
<script setup lang="ts">
const model = defineModel<number>()
</script>
<template>
<button @click="model += 1">inc from setup</button>
</template>
<style scoped>
button {
color: green;
}
</style>
`,
);
export const CounterModule = vueSfc(
"CounterModule",
`
<script lang="ts">
export default {
props: {
modelValue: {
type: Number,
required: true,
},
},
emits: ['update:modelValue'],
}
</script>
<template>
<button @click="$emit('update:modelValue', $props.modelValue + 1)">inc from module</button>
</template>
<style scoped>
button {
color: red;
}
</style>
`,
);
export default function(req: Request) {
return htmlResponse`
${
Layout({
ribbonProps: {
title: 'fork me on val.town',
fork: true,
},
}, {
default: () =>
html`
${vueSfcInline`
<script setup lang="ts">
import { ref } from "vue"
import { CounterSetup, CounterModule } from "${import.meta.url}";
const value = ref(0)
</script>
<template>
<p>counter: {{ value }}</p>
<CounterSetup v-model="value" />
<CounterModule v-model="value" />
</template>
`}
`,
})
}
`;
}
postpostscript-vueexample.web.val.run
February 28, 2024