postJson(data){
return fetch('todo.json', {
method: 'POST',
body: JSON.stringify(data),
headers: {
'Content-Type': 'application/json'
}
})
.then(response => {response.json()})
.then(function(response) {
console.info('fetch()', response);
});
},this.postJson(this.todos)
.then(()=>{
console.log(this.todos)
})
const express = require('express');
const fs = require("fs");
//const bodyParser = require('body-parser')
const app = express();
//const urlencodedParser = bodyParser.urlencoded({ extended: false })
app.use('/', express.static('dist'));
app.post('/todo.json', (req, res) => {
fs.writeFile('dist/todo.json', 'тут должен быть переданный массив из js', (err)=>{
if(err)console.log('err',err)
})
console.log(req)
});
const port = process.env.PORT || 3000;
app.listen(port, () => console.log(`Listen on port ${port}...`));
app.post('/todo.json', (req, res) => { ошибка и нужно вместо '/todo.json', поставить '/' , я прав?
bodyParser
bodyParser
bodyParser
bodyParser
bodyParser
bodyParser
bodyParser
bodyParser
bodyParser
bodyParser
bodyParser
Я делаю POST запрос, и в нем строка json, которая должна уйти в node и там уже записаться в json документ
return fetch("todo.json", {
method: 'POST',
body: JSON.stringify(data),
headers: {
'Content-Type': 'application/json'
}
})
.then(response => {response.json()})//здесь возникает ошибка неожиданного конца: "App.vue:35 Uncaught (in promise) SyntaxError: Unexpected end of JSON input"
.then(function(response) {
console.info('fetch()', response);
});
.then(response => {response.json()})
.then(function(response) {
console.info('fetch()', response);
});