Last active
November 20, 2023 15:31
-
-
Save u007/587969ae3c5ba59ce77b5dd4da5d7da0 to your computer and use it in GitHub Desktop.
vue3 with tsx
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
import { defineComponent, defineProps, defineEmits, defineExpose, ref } from 'vue' | |
import Xx from '@/components/xx' | |
export default defineComponent({ | |
setup () { | |
const props = defineProps() | |
const emitUpdate = defineEmits<{ (e: 'update', value: number): void }>() | |
console.log('emit', emitUpdate) | |
const count = ref(0) | |
function updateCount () { | |
count.value++ | |
// emitUpdate('update', count.value) | |
} | |
defineExpose({ | |
refresh () { | |
count.value = 0 | |
} | |
}) | |
return () => ( | |
<div> | |
<Xx onUpdate={() => { | |
console.log('onUpdate') | |
}}></Xx> | |
</div> | |
) | |
} | |
}) |
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
import { defineComponent, defineProps, defineEmits, defineExpose, ref } from 'vue' | |
export default defineComponent({ | |
props: { | |
}, | |
emits: { | |
update: (value: number) => true, | |
}, | |
setup (props, { emit }) { | |
const count = ref(0) | |
function updateCount () { | |
count.value++ | |
emit('update', count.value) | |
} | |
defineExpose({ | |
refresh () { | |
count.value = 0 | |
} | |
}) | |
return () => ( | |
<div> | |
<h1>aa</h1> | |
<button onClick={updateCount} type="button">Increment</button> | |
<p>Count: {count.value}</p> | |
</div> | |
) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment