D
D
Dima Pautov2022-01-26 22:40:56
Vue.js
Dima Pautov, 2022-01-26 22:40:56

Is it possible to get data from a component that has a dynamic import attached?

Good evening!

There is such a component, inside which a component is connected through dynamic import:

export default {
    name: 'MyComponent',
    components: {
      Test1: () => import('@/components/test1.vue')
    }
  }


I need to access this component and get its entire set of props that are written inside it.
But from the body of MyComponent, I could not find in any way how to refer to the component connected via dynamic import.

The only option is to import the component via a normal import:
import Test1 from '@/components/test1.vue';

  export default {
    name: 'MyComponent',
    components: {
      Test1
    },
    mounted () {
      console.log(Test1.props); // Так я могу получить список всего его свойств и т.п. данные
    }
  }

But it does not suit me, because. I need the component to be connected dynamically. It probably sounds stupid, since it is dynamic, then it seems to be not there yet, but I need to get part of the code from it.

Is it possible?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2022-01-26
@bootd

components: {
  componentName: () => import('...').then(component => {
    console.log(component.default.props);
    return component;
  }),
  ...
},

S
Sergey Levchenko, 2022-01-29
@nuykon

const Test1 = () => import('@/components/test1.vue');

export default {
  name: 'MyComponent',
  components: {
    Test1
  },
  mounted () {
    Test1().then((m) => {
      // Компонент
      console.dir(m.default);
      // Его пропсы
      console.log(m.default.props);
    });
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question