我想要在post vue中单击“编辑”按钮时想要在(editpost.vue)中接收特定帖子的数据以进行编辑,然后对其进行更新
export default {
name: "editPost",
data(){
return{
post : {},
form: new Form({
title : '' ,
description : '',
content : '',
image : ''
})
}
},
created(){
axios.get(`api/editPost/${this.$route.params.id}`)
.then((response)=>{
//this.post = response.data.post;
console.log(response.data)
this.form.fill(response.data.post)
// Vue.set(this.$data, 'post', response.data.post)
})
},
}
</script>
我的app.js
{ path: '/editPost/:id',name: 'editPost', component: require('./components/EditPost.vue').default }
我的路线
Route::get('/editPost/{id}', 'API\PostController@editPost');
我的postController.php编辑功能
public function editPost($id){
$post = Post::find($id);
return response()->json([
'post'=>$post
],200);
}