Answer the question
In order to leave comments, you need to log in
How to dynamically load a Vue component?
I try this way:
<component :is="componentInstance" />
export default {
props: {
component_path: {
type: String // напр., '@views/Accounts/SectionCreate', в webpack.mix.js есть alias '@views': path.join(__dirname, 'resources/js/views')
}
},
computed: {
componentInstance() {
return () => import(`${this.component_path}.vue`)
// Вариант: return () => import(`${this.component_path}.vue`).then(x => x.default)
}
}
}
[Vue warn]: Failed to resolve async component: function () {
return __webpack_require__("./resources/js/components lazy recursive ^.*\\.vue$")("".concat(_this.component_path, ".vue")).then(function (x) {
return x["default"];
});
}
Reason: Error: Cannot find module '@views/Accounts/SectionCreate.vue'
./resources/js/components
, and why he even tries to climb into this folder, because. I don't give any instructions. mix.webpackConfig.output.publicPath = '/'
. Does not help. Answer the question
In order to leave comments, you need to log in
It seems that dynamic import only works for specific folders, so you need something like
import(`path/to/dynamic/components/${this.component_name}.vue`)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question