Skip to content

Commit aef44b5

Browse files
committed
docs: add solid docs
1 parent 1414037 commit aef44b5

File tree

24 files changed

+424
-48
lines changed

24 files changed

+424
-48
lines changed

.prettierrc.cjs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
module.exports = {
2+
// newline string threshold
3+
printWidth: 96,
4+
5+
// Set the number of spaces for each horizontal indentation of the tool
6+
tabWidth: 2,
7+
8+
// Whether to use tab indentation
9+
useTabs: false,
10+
11+
// Whether to add a semicolon at the end of the sentence
12+
semi: true,
13+
14+
// use single quotes
15+
singleQuote: true,
16+
17+
// The last object element character plus a comma
18+
trailingComma: 'none',
19+
20+
// Whether there is a space between the curly braces of the object literal
21+
bracketSpacing: true,
22+
23+
// jsx > Whether to take another line
24+
bracketSameLine: true,
25+
26+
// No need to automatically add @prettier at the beginning of the file
27+
insertPragma: false,
28+
29+
// use lf for line breaks
30+
endOfLine: 'lf',
31+
32+
// Whether the curly braces of the object literal should start on a new line
33+
bracketSameLine: true,
34+
35+
// Whether the arrow function parameters use parentheses
36+
arrowParens: 'avoid',
37+
38+
// Indentation of script and style tags in vue files
39+
vueIndentScriptAndStyle: false,
40+
41+
// Whether a single attribute is on a separate line
42+
singleAttributePerLine: true
43+
};

.prettierrc.js

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { createAlova } from 'alova';
2+
import adapterFetch from 'alova/fetch';
3+
import SolidHook from 'alova/solid';
4+
export const alovaInstance = createAlova({
5+
baseURL: 'https://jsonplaceholder.typicode.com',
6+
statesHook: SolidHook,
7+
requestAdapter: adapterFetch(),
8+
responded: response => response.json()
9+
});

codesandbox@3/01-getting-started/07-combine-framework/react-useRequest.en.jsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@ import { alovaInstance } from './api';
33

44
const App = () => {
55
// Use the alova instance to create a method and pass it to useRequest to send a request
6-
const { loading, data, error, send, update, onSuccess } = useRequest(
6+
const { loading, data, error, send, update } = useRequest(
77
alovaInstance.Get('/todos/1', {
88
cacheFor: 0
99
}),
1010
{
1111
initialData: {}, // Set the initial data of the data state
1212
immediate: true // Whether to send the request immediately, the default is true
1313
}
14-
);
15-
onSuccess(event => {
14+
).onSuccess(event => {
1615
event.method; //The method of the current request
1716
event.data; //Response data of the current request
1817
});

codesandbox@3/01-getting-started/07-combine-framework/react-useRequest.zh.jsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@ import { alovaInstance } from './api';
33

44
const App = () => {
55
// 使用alova实例创建method并传给useRequest即可发送请求
6-
const { loading, data, error, send, update, onSuccess } = useRequest(
6+
const { loading, data, error, send, update } = useRequest(
77
alovaInstance.Get('/todos/1', {
88
cacheFor: 0
99
}),
1010
{
1111
initialData: {}, // 设置data状态的初始数据
1212
immediate: true // 是否立即发送请求,默认为true
1313
}
14-
);
15-
onSuccess(event => {
14+
).onSuccess(event => {
1615
event.method; // 当前请求的method
1716
event.data; // 当前请求的响应数据
1817
});
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { useRequest } from 'alova/client';
2+
import { alovaInstance } from './api';
3+
4+
const App = () => {
5+
// Use the alova instance to create a method and pass it to useRequest to send a request
6+
const { loading, data, error, send, update } = useRequest(
7+
alovaInstance.Get('/todos/1', {
8+
cacheFor: 0
9+
}),
10+
{
11+
initialData: {}, // Set the initial data of the data state
12+
immediate: true // Whether to send the request immediately, the default is true
13+
}
14+
).onSuccess(event => {
15+
event.method; //The method of the current request
16+
event.data; //Response data of the current request
17+
});
18+
19+
const handleSend = () => {
20+
send();
21+
};
22+
const handleUpdate = () => {
23+
update({
24+
data: { title: 'new title' }
25+
});
26+
};
27+
28+
return (
29+
<>
30+
{loading() ? (
31+
<div>Loading...</div>
32+
) : error() ? (
33+
<div>{error().message}</div>
34+
) : (
35+
<div>
36+
<div>Request result: {JSON.stringify(data)}</div>
37+
<button onClick={handleSend}>Manually send request</button>
38+
<button onClick={handleUpdate}>Manually modify data</button>
39+
</div>
40+
)}
41+
</>
42+
);
43+
};
44+
export default App;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { useRequest } from 'alova/client';
2+
import { alovaInstance } from './api';
3+
4+
const App = () => {
5+
// 使用alova实例创建method并传给useRequest即可发送请求
6+
const { loading, data, error, send, update } = useRequest(
7+
alovaInstance.Get('/todos/1', {
8+
cacheFor: 0
9+
}),
10+
{
11+
initialData: {}, // 设置data状态的初始数据
12+
immediate: true // 是否立即发送请求,默认为true
13+
}
14+
).onSuccess(event => {
15+
event.method; // 当前请求的method
16+
event.data; // 当前请求的响应数据
17+
});
18+
19+
const handleSend = () => {
20+
send();
21+
};
22+
const handleUpdate = () => {
23+
update({
24+
data: { title: 'new title' }
25+
});
26+
};
27+
28+
return (
29+
<>
30+
{loading() ? (
31+
<div>Loading...</div>
32+
) : error() ? (
33+
<div>{error().message}</div>
34+
) : (
35+
<div>
36+
<div>请求结果: {JSON.stringify(data)}</div>
37+
<button onClick={handleSend}>手动发送请求</button>
38+
<button onClick={handleUpdate}>手动修改data</button>
39+
</div>
40+
)}
41+
</>
42+
);
43+
};
44+
export default App;

codesandbox@3/01-getting-started/07-combine-framework/svelte-useRequest.en.svelte

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
import { alovaInstance } from './api';
44
55
// Use the alova instance to create a method and pass it to useRequest to send a request
6-
const { loading, data, error, send, update, onSuccess } = useRequest(
6+
const { loading, data, error, send, update } = useRequest(
77
alovaInstance.Get('/todos/1', {
88
cacheFor: 0
99
}),
1010
{
1111
initialData: {}, // Set the initial data of the data state
1212
immediate: true // Whether to send the request immediately, the default is true
1313
}
14-
);
15-
onSuccess(event => {
14+
).onSuccess(event => {
1615
event.method; //The method of the current request
1716
event.data; //Response data of the current request
1817
});

codesandbox@3/01-getting-started/07-combine-framework/svelte-useRequest.zh.svelte

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@ import { useRequest } from 'alova/client';
33
import { alovaInstance } from './api';
44
55
// 使用alova实例创建method并传给useRequest即可发送请求
6-
const { loading, data, error, send, update, onSuccess } = useRequest(
6+
const { loading, data, error, send, update } = useRequest(
77
alovaInstance.Get('/todos/1', {
88
cacheFor: 0
99
}),
1010
{
1111
initialData: {}, // 设置data状态的初始数据
1212
immediate: true // 是否立即发送请求,默认为true
1313
}
14-
);
15-
onSuccess(event => {
14+
).onSuccess(event => {
1615
event.method; // 当前请求的method
1716
event.data; // 当前请求的响应数据
1817
});

codesandbox@3/01-getting-started/07-combine-framework/vueComposition-useRequest.en.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,15 @@ import { useRequest } from 'alova/client';
1313
import { alovaInstance } from './api';
1414
1515
// Use the alova instance to create a method and pass it to useRequest to send a request
16-
const { loading, data, error, send, update, onSuccess } = useRequest(
16+
const { loading, data, error, send, update } = useRequest(
1717
alovaInstance.Get('/todos/1', {
1818
cacheFor: 0
1919
}),
2020
{
2121
initialData: {}, // Set the initial data of the data state
2222
immediate: true // Whether to send a request immediately, the default is true
2323
}
24-
);
25-
onSuccess(event => {
24+
).onSuccess(event => {
2625
event.method; //The method of the current request
2726
event.data; //Response data of the current request
2827
});

0 commit comments

Comments
 (0)