尝试在项目根目录新建一个manifest.json文件,内容如下:
{
"description": "This is a mock server",
"minimum-stability": "dev",
"license": "MIT",
"authors": [
{
"name": "Author",
"email": "author@example.com"
}
],
"require": {
"php": ">=7.1.3"
}
}
然后在项目根目录新建一个server.php文件,内容如下:
<?php
$method = $_SERVER['REQUEST_METHOD'];
if ($method == 'GET') {
$data = [
'code' => 200,
'msg' => 'success',
'data' => [
'name' => 'mock',
'age' => 18
]
];
echo json_encode($data);
}
最后在uniapp中发起请求:
uni.request({
url: 'http://localhost/server.php',
success: (res) => {
console.log(res.data);
}
});