Skip to content

Instantly share code, notes, and snippets.

@mizchi
Created June 30, 2020 11:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mizchi/f083778cd61378b87d41a728aa4f4aea to your computer and use it in GitHub Desktop.
Save mizchi/f083778cd61378b87d41a728aa4f4aea to your computer and use it in GitHub Desktop.
<template>
<div>
<Sub message="hello" />
</div>
</template>
<script lang="ts">
import {
defineComponent,
reactive,
ref,
onUpdated,
onMounted,
onUnmounted,
} from '@vue/composition-api';
import Sub from './sub.vue';
export default {
components: {
Sub,
},
setup(props) {
onMounted(() => console.log('mounted'));
onUpdated(() => console.log('updatede'));
return {};
},
};
</script>
<template>
<div>
<h2>Sub: {{ message }}</h2>
<div>{{ count }}</div>
<button @click="increment">++</button>
</div>
</template>
<script lang="ts">
import {
defineComponent,
reactive,
PropType,
ref,
onUpdated,
onMounted,
onUnmounted,
} from '@vue/composition-api';
type Props = { message: string };
const useCounter = () => {
const count = ref(0);
const increment = () => {
count.value++;
};
return { count, increment };
};
export default defineComponent<Props>({
name: 'Sub',
props: {
message: {
type: String as PropType<string>,
required: true,
},
},
setup(props) {
const { count, increment } = useCounter();
return {
count,
message: props.message as any,
increment,
};
},
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment