问题描述
我有一个带有Vue.js的应用程序,在一种方法中,我创建了一个简单的访存程序以发布到我的API,但是只有_id
被保存在mongodb中。
我在Vuejs应用程序中的方法(我使用json创建了一个变量来测试我的提取信息)
saveAllResults(){
let myvalue ='{"Step2":[{"selected":!1,"produto":"A70-5","ncm":"9506.62.00","aliqII":.2,"aliqIpi":0,"aliqPis":.021,"aliqCofins":.0965,"descricao":"BOLA DE BASQUETE","pesoUnitario":.43,"unitario":.78,"dumping":0,"cubagemUnitario":0,"quantidade":150,"icmEstadoDestino":0,"mvaAjustado":0,"markup":.12},{"selected":!1,"produto":"PINK-7-103","ncm":"7117.90.00","aliqII":.18,"aliqIpi":.12,"descricao":"BIJOUTERIAS EM METAL/ VIDRO ","pesoUnitario":.975,"unitario":1.52,"quantidade":200,"markup":.11},"quantidade":300,"markup":.19}],}';
fetch('http://localhost:4242/api/v1/dis',{
method: 'post',body: myvalue
}).then(function(response){
return response.json(myvalue);
}).then(function(text){
console.log(text);
}).catch(function (error){
console.error(error);
})
}
我在API中的路线(我在mongoDB中使用express,morgan,joi,头盔,cors,bodyParse)
// CREATE ONE
router.post('/',async (req,res,next) => {
try {
const value = await schema.validateAsync(req.body);
const inserted = await dis.insert(value);
res.json(inserted);
} catch (error) {
next(error);
}
});
当我尝试使用Isominia(或邮递员)投递相同的json数据时,投递工作正常,但是对于我的fecth投递请求,仅生成_id
且不投递所有数据我想要的。
“提取帖子”在控制台中返回:
{_id: "5f376d6edd37760c6632c8ab"}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)