项目场景:
提示:打包配置后端地址和读取一些静态文件
前端js读取本地json文件
解决方案:
提示:这里填写该问题的具体解决方案:
方法一:
const fs = require('fs')
const data = fs.readFileSync('./static/localUrl.json', 'utf8').toString().replace(/[ ]|[\r\n]/g,"")
const json = JSON.parse(data)
方法二:
fetch('./static/localUrl.json').then((response) => response.json())
.then((json) => {
const serveId = json.id
})