Skip to content

Instantly share code, notes, and snippets.

@u007
Last active November 20, 2023 15:31
Show Gist options
  • Save u007/587969ae3c5ba59ce77b5dd4da5d7da0 to your computer and use it in GitHub Desktop.
Save u007/587969ae3c5ba59ce77b5dd4da5d7da0 to your computer and use it in GitHub Desktop.
vue3 with tsx
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>
)
}
})
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