sfc setup script can not call child method
Version
3.2.4
Reproduction link
Steps to reproduce
I create a button that has a logger method , it write under <script setup lang=''ts'>. I also create a component using that button.
<template>
<button class="btn" @click="onClick">{{ label }}</button>
this is new value
<div>{{ foo }}</div>
</template>
<script setup lang="ts">
import { ref, defineProps, defineEmits } from 'vue'
const props = defineProps({
foo: String
})
const emit = defineEmits(['change', 'delete'])
const label = ref("I'm a very dangerous button")
const onClick = () => {
label.value = "Don't touch me"
console.log(control.getBooksRoute())
emit('change')
}
const log = () => {
console.log('hello ')
}
</script>
parent component is
<template>
<div class="about">
<h1>This is an about page</h1>
</div>
<my-button ref="button" foo="hello"></my-button>
<button @click="onclicked">clicked child</button>
</template>
<script setup lang="ts">
import MyButton from '@/components/MyButton.vue'
import { ref } from 'vue'
const button = ref(null)
const onclicked = () => {
button.value.log()
}
</script>
What is expected?
i call child method from parent , I expect I can call child method.
What is actually happening?
Uncaught TypeError: button.value.log is not a function
you should add defineExpose in child component.