Answer the question
In order to leave comments, you need to log in
How to make auto import in Vue?
I continue to understand Vue.js,
There is a request to the server => the server pulls the necessary data and which components should be used (componentName: 'componentPath'):
used_components:
{
first: '@/components/first',
second: '@/components/second'
},
......
.....
name: 'Page',
components: {
first: () => import('@/components/first'),
second: () => import('@/components/second')
},
data () {
return {
server_array: '',
server_components: ''
}
},....
name: 'Page',
components: server_components, // из даты берём (или как-то подругому)
data () {
return {
server_array: '',
server_components: '' //переопределим через methods
}
},
beforeMount () {
this.getPage()
},
methods: {
async getPage () {
const response = await Page.getPage()
this.server_components = response.data.used_components
this.setComponents(this.server_components)
},
setComponents (data) {
for (var key in data) {
() => import(data[key])
}
}
}
....
Answer the question
In order to leave comments, you need to log in
data: {
componentName: ""
}
async getPage () {
const response = await Page.getPage()
this.componentName = ...
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question