Reputation: 22804
Usually we define in a Nuxt.js component something like this:
<script>
export default {
components: {
// components
}
data() {
return {
// key/value data
}
},
methods: {
// method definitions
}
}
</script>
Is there a way to read the components
object as we read data()
and methods
?
This is because I have several components and I want to loop on them to refactor parts of my code.
Upvotes: 1
Views: 198
Reputation: 6978
You can get Component data by using $options. Try this.
created() {
console.log(this.$options.components)
}
it returns an object, keys are the component names, values are the contructors.
codepen - https://codesandbox.io/s/yk9km5m0wv
Upvotes: 2