I am using VueJS for the first time and enjoying it. I am trying to POST to a page, GET works fine
In my routing file I have all the routes mapped out, I am trying to post to Contracts
{ path: '/contract/:id',
name: 'Contract2',
component: Contract,
props: true
},
If I do a GET /contract?id=1 or /contract/1 both work with GET
But POST (Postman for instance) I get
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot POST /contract/</pre>
</body>
</html>
My VueJS posting code (the redirect is not working either)
loadContract: function(contractId) {
axios
.post("/contract", {
id: contractId
})
.then(function(response) {
console.log(response);
//REDIRECT TERE
//router.go("/contract");
})
.catch(function(error) {
console.log(error);
});
},
答案 0 :(得分:2)
你的意思是发布到另一个页面?如果您正在讨论使用vue-router在页面之间传递数据,那么在进行编程导航时,您实际上可以传递参数。请阅读here
示例:
router.push({ name: 'contract', params: { contractId: 123 }})