简体   繁体   中英

How do I pass variables/data from a JS file to an HBS file?

I am pulling database data in the 1st JS file, controller.js.

I need to pass it to the front-end file that's making use of the data to display it/graph it.

Call it, view.hbs

I tried:

controller.js: data.exports={data};

view.hbs const { data } = require('Project/views/controller.js')

But I get a "ReferenceError: require is not defined".

Not sure if there's an alternative way to pass data/variables.

require is function that is available in node environment.

If you want to use it in browser you need to compile code using webpack for example.

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