Skip to content

Add inferred component name(__name) to <script> #6357

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

Open
zhuscat opened this issue Jul 26, 2022 · 1 comment
Open

Add inferred component name(__name) to <script> #6357

zhuscat opened this issue Jul 26, 2022 · 1 comment
Labels
✨ feature request New feature or request

Comments

@zhuscat
Copy link

zhuscat commented Jul 26, 2022

What problem does this feature solve?

compiler-sfc adds __name property to <script setup>, but it does not adds __name property to regular <script>. Is it appropriate to add __name to all types of <script> so I can get inferred name if one component does not have a name property.

What does the proposed API look like?

In all conditions, I can get __name:

export default {
  mounted() {
    console.log(this.$options.__name)
  }
}
<script setup>
const inst = getCurrentInstance().proxy
onMounted(() => {
  console.log(inst.$options.name)
})
</script>
@zhuscat zhuscat added the ✨ feature request New feature or request label Jul 26, 2022
@jh-leong
Copy link
Member

If you only need the component name, you can retrieve it using the following code within the setup function: getCurrentInstance().proxy.$options.name. When you use Single-File Components, the component already infers its own name from the filename.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ feature request New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants