This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div> | |
<recursive-component></recursive-component> | |
</div> | |
</template> | |
<script lang="ts"> | |
import { defineComponent } from 'vue' | |
export default defineComponent({ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function countDown(fromNumber) { | |
console.log(fromNumber) | |
let nextNumber = fromNumber - 1 | |
if (nextNumber > 0) { | |
countDown(nextNumber) // 呼叫自己 | |
} | |
} | |
countDown(5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Parent Component | |
<template> | |
<div> | |
<parent-recursive-component @recursiveEmit="recursiveEmit" /> | |
</div> | |
</template> | |
<script lang="ts"> | |
import { defineComponent } from 'vue' | |
import ParentRecursiveComponent from './RecursiveComponent' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ChildComponent v-model="pageTitle" /> | |
// v-model 是下面寫法的語法糖: | |
<ChildComponent :value="pageTitle" @input="pageTitle = $event" /> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ChildComponent.vue | |
export default { | |
model: { | |
prop: 'title', | |
event: 'change' | |
}, | |
props: { | |
// title 取代 value | |
title: { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ChildComponent :title="pageTitle" @change="pageTitle = $event" /> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ChildComponent.vue | |
<script> | |
export default { | |
props: { | |
title: { | |
type: String, | |
default: 'Default title' | |
} | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ChildComponent :title.sync="pageTitle" /> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ChildComponent v-model="pageTitle" /> | |
// v-model 是下面寫法的語法糖: | |
<ChildComponent | |
:modelValue="pageTitle" | |
@update:modelValue="pageTitle = $event" | |
/> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ChildComponent v-model:title="pageTitle" /> | |
// v-model:title 是下面寫法的語法糖: | |
<ChildComponent :title="pageTitle" @update:title="pageTitle = $event" /> | |
OlderNewer