Y
Y
Yasuro2019-09-19 10:00:51
JavaScript
Yasuro, 2019-09-19 10:00:51

How to dynamically import a vue.js module?

Hello.
I need to get the name of the module from props.
I did this and it works:

<template>
  <div>
    <component :is="componentLoader" :parent="response.parent"></component>
  </div>
</template>


<script>
export default {
  props: ["response"],

  computed: {
    componentLoader() {
      this.response; //Если я вызову response тут...
      return () => {
        this.parent = this.response.tempParam; // то здесь я смогу получить доступ к tempParam, в противном случае получается undefined
        return import("./response/" + this.parent);
      };
    }
  }
};
</script>>

<style scoped>
</style>

But the problem is that I'm hardcore about this.parent, but I want to get it from response. If I do this.response.parent then I get undefined.
If you suggest another implementation, I will be glad.
I am using webpack.
ps https://codeshare.io/5zeNkD

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
HeTpe3B, 2019-09-19
@Yasuro

new Vue({
  // ...
  components: {
    'my-component': () => import('./my-async-component')
  }
})

https://vuejs.org/v2/guide/components-dynamic-asyn...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question