我目前正在尝试使用角度功能,但我不能在react应用程序中使用ng-click。
我正在尝试将下面的函数转换为react函数,我知道
axios
,不知道如何处理react中的叶片变量。
我需要将角度片段转换为react函数。
角度(main.js)
$scope.myfollow = function(user) {
$http.post('/user/follow/'+ user.id).then(function(result) {
console.log("user id is:"+ user.id);
});
};
反应文件
render(){
return(
<div className="followdoe">
<button onClick={ this.btnClick.bind(this) } className={this.state.className}>
<p>{ this.state.btnText }</p>
</button>
</div>
)
}
route.php路径
Route::post('user/follow/{id}', 'UserController@my_follow');
profile.blade.php文件
<div style="margin:30px 0px;">
<button class="follow-button" ng-click="myfollow({{$user}});">+ Follow</button>
</div>
usercontroller.php用户控制器
public function my_follow(Request $request, $id)
{
$user = auth()->user();
if($user->id != $id && $otherUser = User::find($id)){
$user->toggleFollow($otherUser);
}
}
public function getProfile($user)
{
$user = User::with(['posts.likes' => function($query) {
$query->whereNull('deleted_at');
}, 'follow','follow.follower'])
->where('name','=', $user)->first();
if(!$user){
return redirect('404');
}
return view ('profile')->with('user', $user);
}