有一段代码使用axios-mock-adapter并通过GET请求返回一个对象:
mock.onGet('/api/auth').reply((config) => {
const data = JSON.parse(config.data);
const {email, password} = data;
const user = _.cloneDeep(authDB.users.find(_user => _user.data.email === email));
const error = {
email : user ? null : 'Check your username/email',
password: user && user.password === password ? null : 'Check your password'
};
if ( !error.email && !error.password && !error.displayName )
{
delete user['password'];
const access_token = jwt.sign({id: user.uuid}, jwtConfig.secret, {expiresIn: jwtConfig.expiresIn});
const response = {
"user" : user,
"access_token": access_token
};
return [200, response];
}
else
{
return [200, {error}];
}
});
User是具有各种值的JSON对象。这怎么可能? URL中会是什么样?我正在研究代码块,以了解如何在没有axios-mock-adapter的情况下做到这一点。