.then(response => {response.json()})
.then(function(response) {
console.info('fetch()', response);
});
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);
});
app.post('/todo.json', (req, res) => {
ошибка и нужно вместо '/todo.json', поставить '/' , я прав? 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.use('/', express.static('dist'));
как раз и указывает на dist const express = require('express');
const fs = require("fs");
const app = express();
app.use('/', express.static('dist'));
app.use(express.json());
app.post('/todo.json', (req, res) => {
let objJSON = req;
fs.writeFile('/todo.json', objJSON, (err) => {
if(err){
console.log(err)
}
})
})
const port = process.env.PORT || 3000;
app.listen(port, () => console.log(`Listen on port ${port}...`));
postJson(url, data){
return fetch(url, {
method: 'POST',
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(data)
})
.then(result => result.json())
},
this.postJson('todo.json', this.todos).
then(data => {
data = this.todos
})