Is it possible to do something like
import Vue from '../vendor/vue';
import slides from '../data/'+$root.name'+.json';
Vue.component('mycomponent', {
Is it possible to do something like
import Vue from '../vendor/vue';
import slides from '../data/'+$root.name'+.json';
Vue.component('mycomponent', {
No, unfortunately import statements must use static names.
There is a proposal to add a dynamic module()
function that will load on the fly: https://github.com/tc39/proposal-dynamic-import
The proposed syntax is:
import('./' + dynamicFileName + '.js')
.then(module => {
// use module
})
.catch(err => {
// handle error
});
It looks to be currently active: https://github.com/tc39/proposals
It looks like there is a polyfill here: https://github.com/ModuleLoader/es-module-loader
Another issue is that you can't directly import json into JavaScript. The below approach might be what you're after:
Slides file:
export const slides = [
{ ... }
];
Then import the file with either a static module path or with the dynamic import polyfill.