好的,下班了,回去仔细想一下,多谢Jelly
laravel版本是5.2
api 路由的定义是否是在 api.php 里面
你说的是api中间件吗,我并没有注册这个,我不知道应该怎么操作才能像你视频中说的在中间件中自动加上api/的路由前缀
axios.get 可以正常获得数据,axios.post提示跨域请求
服务端路由
Route::post('api/todo/create', function (Request $request){
$data = ['title' => $request->get('title'),'completed' => 0];
$todo = App\Todo::create($data);
return $todo;
})->middleware('cors');
TodoForm组件
methods: {
addTodo(newTodo){
this.axios.post(
'http://localhost:8000/api/todo/create',{title: this.newTodo.title}).then(response => {
console.log(response.data)
})
this.todos.push(newTodo);
this.newTodo = {id:39,title:'',completed:false};
},
}