Javascript 如何从服务器发送json文件数组?

Javascript 如何从服务器发送json文件数组?,javascript,node.js,vue.js,Javascript,Node.js,Vue.js,我正在使用vue.js。我已经写了下面的代码,但它不工作,我如何修复它 这是我的密码: mounted(){ 获取(“/”{ 方法:'POST'、/*GET、POST、PUT、DELETE等。 模式:'cors',//无cors,*cors,同一来源 标题:{ “内容类型”:“应用程序/json”, “接受”:“应用程序/json” }, }) .then(response=>response.json()) .then(json=>this.firstWindow=json) //.then(

我正在使用vue.js。我已经写了下面的代码,但它不工作,我如何修复它

这是我的密码:

mounted(){
获取(“/”{
方法:'POST'、/*GET、POST、PUT、DELETE等。
模式:'cors',//无cors,*cors,同一来源
标题:{
“内容类型”:“应用程序/json”,
“接受”:“应用程序/json”
},
})
.then(response=>response.json())
.then(json=>this.firstWindow=json)
//.then(json=>console.log(json))
//.then(console.log(this.firstWindow))
},
这里是服务器部件

router.post('/',(req,res)=>{//发送文件的请求
控制台日志(“POST”);
//res.sendFile(myModule.dataOfScreens);
res.sendFile(path.resolve('./data/firstScreen.json');
})

您正试图从服务器获取文件,但您使用的是POST方法

如果这是您的目标,那么您应该这样做:

router.get('/filesFolder?:fileName', function(req, res){
    let filePath = '.. the path of your local files folder ..+ '/' +req.query.fileName
    if (fs.existsSync(filePath)) {
      //file exists
      res.sendFile(filePath);
    }
  });

其中filefolder是存储文件的文件夹的名称;fileName是您请求的文件的名称;filePath是请求文件的FileFolder下的路径。

“这绝对是错误的”-它怎么错了?它不工作……我不知道如何发送和处理此数组,对吗?是否要从客户端(vuejs)向服务器发送JSON数组?从服务器到客户端