I wish to reference the js data file in the framework
I write like this
import Configs from "../data/configs";
console.log(Configs);
in chrome no output
use export same not working
const Configs = [
{
"id": 0,
"cover": "1.webp"
}
]
export default Configs
2
Answers
Try to put the
console.log
in<script>
like thisSee more details for the client side script:
console.log()
Not entirely clear what framework you are using client side but some documentation for you to look through for this is here if working with React/Vue etc. Otherwise to run standard JS with all code contained within the .astro file then passing your console log within a script tag will get the outcome you want.
To summarise what is happening, you’ve written the import and console log within the — brackets. This is marking code to run on server side for this page. This will result in the log only appearing within a server console, with the client being completely unaware of any of this happening. Adding the script tags and the log within there is you telling the client to print that log.
Worth noting though if you are only wanting to examine the code in the console then as I said before it will be appearing in the terminal where you ran your command to host your dev code.