PHP如何接受axios传递的参数

PHP如何接受axios传递的参数
我们在做vue项目的时候一般都用axios发送请求,那后端php怎么接受前端传递的数据呢?举个例子,用户登录

axios.post(‘/api/user/loginin’, {
username: this.username,
password: this.password
}).then(res => {
console.log(res)
}).catch(err => console.log(err))

我们一般都这么写前端请求,后端PHP接收数据一般是这种形式

$username = $_POST[‘username’];
$password = $_POST[‘password’];

那问题来了,这么写后端是获取不到数据的,所以我们前端得换一种传递参数的方式

var params = new URLSearchParams()
params.append(‘username’, ‘我叫胡八一’)
params.append(‘password’, ‘qq:1627889159’)
axios.post(‘/api/user/loginin’, params).then(res => {
console.log(res)
}).catch(err => console.log(err))

这样后端就能成功接收到数据了