*在usersedit.blade.php中:
new Vue({
el : '#user_type',
data : {
password : ['type','newpassword','repeatpassword'],
newpassword : ['type','newpassword','repeatpassword']
},
ready: function() {
this.$http.get('showUser').then((response) => {
console.log(response);
this.$set('password', response.data)
}, (response) => {
console.log(response);
});
},
methods: {
changePwd:function () {
this.$http.get('updateUser').then((response) => {
console.log(response);
this.$set('newpassword', response.data)
}, (response) => {
console.log(response);
});
}
}
});
*在ConfigController.php中:
public function showUser()
{
$user_type = $_GET['type'];
$result = DB::table('cmt_admin_users')
->where('type', $user_type)
->get();
return json_encode($result);
}
public function updateUser(Request $request)
{
$user_type = $_GET['type'];
$user_password = $_GET['newpassword'];
$result = DB::table('cmt_admin_users')
->where('type', $user_type)
->update(['password' => $user_password]);
if ($result){
$msg = "update user success";
return response()->json(array('msg'=> $msg), 200);
}else{
$msg = "update user failure";
return response()->json(array('msg'=> $msg), 405);
}
}
ready:function请求有返回数据,chrome打印内容: {url: "showUser", ok: true, status: 200, statusText: "OK", headers: t…},但返回的body内容为整个html页面,求大神们指导。