mirror of
https://github.com/robonen/canvas-3d.git
synced 2026-03-20 02:44:40 +00:00
feat(components): HtmlElementEvent type and canvas testing
This commit is contained in:
@@ -12,7 +12,7 @@ const showForm = ref<boolean>(false);
|
||||
<IconOpen v-else/>
|
||||
</button>
|
||||
</div>
|
||||
<div class="content" v-if="showForm">
|
||||
<div class="content" v-show="showForm">
|
||||
<slot/>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
18
src/components/board.vue
Normal file
18
src/components/board.vue
Normal file
@@ -0,0 +1,18 @@
|
||||
<script setup lang="ts">
|
||||
const canvas = ref<HTMLCanvasElement | null>(null);
|
||||
|
||||
onMounted(() => {
|
||||
if (!canvas.value) return;
|
||||
|
||||
const ctx = canvas.value.getContext("2d");
|
||||
|
||||
if (!ctx) return;
|
||||
|
||||
ctx.fillStyle = "red";
|
||||
ctx.fillRect(0, 0, Math.random() * 100, Math.random() * 100);
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<canvas ref="canvas" />
|
||||
</template>
|
||||
@@ -1,4 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import {HTMLElementEvent} from '@/types/dom';
|
||||
|
||||
const {
|
||||
label,
|
||||
min,
|
||||
@@ -14,10 +16,10 @@ const emit = defineEmits<{
|
||||
const value = ref<number>(defaultValue);
|
||||
|
||||
const onChange = (event: Event) => {
|
||||
value.value = (event.target as HTMLInputElement).valueAsNumber;
|
||||
const {target} = event as HTMLElementEvent<HTMLInputElement>;
|
||||
value.value = target.valueAsNumber;
|
||||
emit('change', value.value);
|
||||
};
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
|
||||
const showMenu = ref<boolean>(true);
|
||||
</script>
|
||||
|
||||
@@ -17,7 +18,7 @@ const showMenu = ref<boolean>(true);
|
||||
</button>
|
||||
</template>
|
||||
</div>
|
||||
<canvas class="canvas"/>
|
||||
<Board class="canvas"/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
3
src/types/dom.ts
Normal file
3
src/types/dom.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export type HTMLElementEvent<T extends HTMLElement> = Event & {
|
||||
target: T;
|
||||
}
|
||||
Reference in New Issue
Block a user