简体   繁体   中英

How to dynamically import JavaScript files in controllers?

I have one same form, where I pass data from 10 different components, including the ID of each table, I want to get from the DB the data by ID . The problem is that my code that asyncs the data is in 10 different .js controllers. For example, to get data of User from the DB, I should import /path/.../userController.js on the beginning of the script section. I parsed some string and got as result:

var path = /path/.../javascriptController

But, I get of course an error if I call on the top of the script section this:

import Controller from path; 

Is it possible to import with any way .js files like:

import Controller from {{ path }}

How do I solve this problem?

Do you have an export default in your javascriptController.js ?

export default

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM