-
-
Notifications
You must be signed in to change notification settings - Fork 392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
In 0.31.1, when I wanted to export a type in a component, I had to put it in the header #901
Comments
Does <script lang="ts">
import { defineComponent } from 'vue'
export interface ModalExpose {
changeLoading: typeof changeLoading // Cannot find name 'changeLoading'.ts(2304)
}
export default defineComponent({
setup(_, { expose }) {
const changeLoading = 0;
expose({ changeLoading })
return { changeLoading }
},
});
</script> But I think you don't need to define expose interface, you can use InstanceType to extract exposes properties in script setup already. A.vue: <script lang="ts" setup>
import { ref } from 'vue'
const count = ref(0)
defineExpose({ count })
</script> B.vue: <script lang="ts" setup>
import { ref, onMounted } from 'vue'
import A from './components/A.vue'
const a = ref<InstanceType<typeof A>>()
onMounted(() => {
a.value?.count // number | undefined
})
</script> |
No, |
Now I have to write it this way:
But how does this relate to function types? |
Please show me your code that when to use |
child.vue
father.vue
If I delete the open type export, the editor will prompt me: |
You don't need child.vue <script lang="ts" setup>
const dialogFormVisible = ref(false)
const id = ref('')
function open(Id = '', ids = '') {
id.value = Id
dialogFormVisible.value = true
}
defineExpose({ open })
</script> father.vue <script lang="ts" setup>
import roleModal from '@/components/roleModal.vue'
const roleModalRef = ref<InstanceType<typeof roleModal>>()
function handleEmpower(index: number, row: Row) {
roleModalRef.value?.open(row.roleId, row.resourceIds)
}
</script> |
Maybe I didn't make it clear, but roleModal components are encapsulated by Modal component.
I found that in the Modal component, |
roleModal.vue
Here I can delete ModalExpose. |
Same with |
Thank you, I have found the cause of the error, you are right, I might not have found this problem if it was not for volar update. |
If I write this, I get an error, but if I put it in the header, it says
changeLoading
is undefined, and if I putchangeLoading
in the header, I get an error, which makes me very frustratedThe text was updated successfully, but these errors were encountered: