我正在使用 Redux Toolkit 通过 Axios 连接到 API。我正在使用以下代码:
const products = createSlice({
name: "products",
initialState: {
products[]
},
reducers: {
reducer2: state => {
axios
.get('myurl')
.then(response => {
//console.log(response.data.products);
state.products.concat(response.data.products);
})
}
}
});
Run Code Online (Sandbox Code Playgroud)
axios 正在连接到 API,因为打印到控制台的注释行向我显示了数据。但是, state.products.concat(response.data.products); 抛出以下错误:
类型错误:无法在已撤销的代理上执行“获取”
有没有办法解决这个问题?
有没有办法使用 URL 在 AJV 中加载 json 模式。我使用此代码从mockable.io 加载json 模式。
var ajv = new Ajv({ loadSchema: loadSchema });
ajv.compileAsync("http://demo3880044.mockable.io/").then(function (validate) {
var valid = validate(data);
});
function loadSchema(uri) {
return request.json(uri).then(function (res) {
if (res.statusCode >= 400)
throw new Error('Loading error: ' + res.statusCode);
return res.body;
});
}
Run Code Online (Sandbox Code Playgroud)
但我收到此错误:
Error: schema should be object or boolean
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
感谢您的帮助。