|
|
před 2 roky | |
|---|---|---|
| .. | ||
| .vscode | před 2 roky | |
| demo | před 2 roky | |
| public | před 2 roky | |
| src | před 2 roky | |
| .editorconfig | před 2 roky | |
| .env.dev | před 2 roky | |
| .env.prod | před 2 roky | |
| .gitignore | před 2 roky | |
| README.md | před 2 roky | |
| canvas.md | před 2 roky | |
| index.html | před 2 roky | |
| package.json | před 2 roky | |
| pnpm-lock.yaml | před 2 roky | |
| tsconfig.json | před 2 roky | |
| tsconfig.node.json | před 2 roky | |
| vite.config.ts | před 2 roky | |
Vue 3 + TypeScript + Vite
<!-- 子组件 -->
<template>
<h1>ts sample</h1>
<p>{{ msg }}</p>
</template>
<script setup lang="ts">
// 第一种方式:分离模式
interface Props {
msg?: string | number | boolean;
title?: string[];
}
withDefaults(defineProps<Props>(), {
msg: "hello",
title: () => ["one", "two"],
});
// 第二种方式:组合模式
withDefaults(defineProps<{ msg?: string | number | boolean; title?: string }>(), {
msg: "hello vite",
title: "默认标题",
});
// 第三种方式:利用接口声明类型
interface testType {
name: string;
age: number;
}
const props = withDefaults(
defineProps<{
text: testType;
}>(),
{
text: {
name: "flying_dark_feather",
age: 20,
},
}
);
</script>