How to programmatically register components in script setup? #6780
              
                
                  
                  
                    Answered
                  
                  by
                    itchwoot
                  
              
          
                  
                    
                      itchwoot
                    
                  
                
                  asked this question in
                Help/Questions
              
            -
| Hi! With the options API, I can do a bulk import and register components from a destructured object: <script>
import icons from '@my-ui-components/icons/all-icons.js';
export default {
    name: 'MyComponent',
    components: { ...icons },
}
</script>How can I achieve this with  | 
Beta Was this translation helpful? Give feedback.
      
      
          Answered by
          
            itchwoot
          
      
      
        Oct 7, 2022 
      
    
    Replies: 2 comments 8 replies
-
| You can use like this: Before import you can check the js file export is default exports or named exports. App.vue <script setup>
import { ref } from 'vue'
import { HelloWorld } from './lib-es.js'
const msg = ref('This is from App')
</script>
<template>
  <HelloWorld :msg="msg" />
  <input v-model="msg" />
</template>lib-es.js import { ref as o, openBlock as r, createElementBlock as n, toDisplayString as t } from "vue";
const a = {
  __name: "HelloWorld",
  props: {
    msg: String
  },
  setup(e) {
    const l = o("Hello World!");
    return (s, c) => (r(), n("h1", null, t(e.msg || l.value), 1));
  }
};
export {
  a as HelloWorld
}; | 
Beta Was this translation helpful? Give feedback.
                  
                    8 replies
                  
                
            -
| Solution: <script setup>
import { computed } from "vue";
import icons from "./icon.js";
const props = defineProps({
  iconComponentName: {
    type: String,
    default: "Icon1",
  },
});
const actualComponentName = computed(() => {
  return icons[props.iconComponentName];
});
</script> | 
Beta Was this translation helpful? Give feedback.
                  
                    0 replies
                  
                
            
      Answer selected by
        itchwoot
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
Solution: