安装axios
在vue目录内执行以下命令安装axios
npm i axios -S
获取管理员接口数据
public function UserLists (){
$user = Db::table('yj_admin')->select()->toArray();
if (!empty($user)){
foreach ($user as &$user_v){
if ($user_v['status'] == 1){
$user_v['status_s'] = '开启';
}else{
$user_v['status_s'] = '关闭';
}
$user_v['add_time'] = date('Y-m-d',$user_v['add_time']);
$user_v['last_time'] = date('Y-m-d',$user_v['last_time']);
}
}
$json = json_encode($user);
echo $json;
}
增加管理员接口
public function UserSave(){
$post = input('post.');
//print_r($post);
$data = [
'account' => $post['account'],
'password' => md5($post['password']),
'name' => $post['name'],
'phone' => $post['phone'],
'status' => $post['status'],
'add_time' => time()
];
$insert = Db::table('yj_admin')->insert($data);
if(empty($insert)){
$arr = [
'code' => 1,
'msg' => '失败'
];
}else{
$arr = [
'code' => 0,
'msg' => '成功'
];
}
echo json_encode($arr);
}