1
1
<script setup lang="ts">
2
2
import { router , usePage } from ' @inertiajs/vue3' ;
3
3
import { ref , unref } from ' vue' ;
4
+ import { globalState } from ' @/utils/globalState' ;
5
+ import Spinner from ' @/components/Spinner.vue' ;
4
6
5
7
const page = usePage <{
6
8
nowDirect: string ;
@@ -10,7 +12,7 @@ const page = usePage<{
10
12
}>();
11
13
12
14
const lastProps = ref (unref (page .props ));
13
-
15
+ const loadingNowLazyAsync = ref ( false );
14
16
function reloadRouter(opts ? : any ) {
15
17
lastProps .value = unref (page .props );
16
18
router .reload (opts );
@@ -25,13 +27,18 @@ function reloadRouter(opts?: any) {
25
27
<pre class =" text-xs bg-gray-100 dark:bg-gray-900 p-3 mb-10 rounded-md" >
26
28
public IActionResult Index()
27
29
{
28
- var now = DateTime.UtcNow.ToString("O").Split('T')[1].Replace(".", " " );
30
+ var now = GetNow( );
29
31
return Inertia.Render("pages/PageIndex", new InertiaProps
30
32
{
31
33
["NowDirect"] = now,
32
34
["NowFunc"] = () => now,
33
35
["NowAlways"] = Inertia.Always(() => now),
34
36
["NowLazy"] = Inertia.Lazy(() => now),
37
+ ["NowLazyAsync"] = Inertia.Lazy(async () =>
38
+ {
39
+ await Task.Delay(2000);
40
+ return now;
41
+ }),
35
42
});
36
43
}</pre
37
44
>
@@ -46,7 +53,7 @@ public IActionResult Index()
46
53
</tr >
47
54
<tr >
48
55
<td class =" font-bold pr-4" >NowFunc</td >
49
- <td class =" font-mono" style =" width : 200px ; " >{{ page.props.nowFunc }}</td >
56
+ <td class =" font-mono" style =" width : 200px " >{{ page.props.nowFunc }}</td >
50
57
<td class =" font-bold pl-4" :class =" lastProps.nowFunc == page.props.nowFunc ? '' : 'text-green-600'" >({{ lastProps.nowFunc == page.props.nowFunc ? 'same' : 'changed' }})</td >
51
58
</tr >
52
59
<tr >
@@ -55,9 +62,14 @@ public IActionResult Index()
55
62
<td class =" font-bold pl-4" :class =" lastProps.nowAlways == page.props.nowAlways ? '' : 'text-green-600'" >({{ lastProps.nowAlways == page.props.nowAlways ? 'same' : 'changed' }})</td >
56
63
</tr >
57
64
<tr >
58
- <td class =" font-bold pr-4" >NowLazy</td >
59
- <td class =" font-mono" style =" width : 200px " >{{ page.props.nowLazy }}</td >
60
- <td class =" font-bold pl-4" :class =" lastProps.nowLazy == page.props.nowLazy ? '' : 'text-green-600'" >({{ lastProps.nowLazy == page.props.nowLazy ? 'same' : 'changed' }})</td >
65
+ <td class =" font-bold pr-4" >NowLazy</td >
66
+ <td class =" font-mono" style =" width : 200px " >{{ page.props.nowLazy }}</td >
67
+ <td class =" font-bold pl-4" :class =" lastProps.nowLazy == page.props.nowLazy ? '' : 'text-green-600'" >({{ lastProps.nowLazy == page.props.nowLazy ? 'same' : 'changed' }})</td >
68
+ </tr >
69
+ <tr >
70
+ <td class =" font-bold pr-4" >NowLazyAsync</td >
71
+ <td class =" font-mono" style =" width : 200px " >{{ page.props.nowLazyAsync }}</td >
72
+ <td class =" font-bold pl-4" :class =" lastProps.nowLazyAsync == page.props.nowLazyAsync ? '' : 'text-green-600'" >({{ lastProps.nowLazyAsync == page.props.nowLazyAsync ? 'same' : 'changed' }})</td >
61
73
</tr >
62
74
</tbody >
63
75
</table >
@@ -68,6 +80,12 @@ public IActionResult Index()
68
80
<button @click =" reloadRouter({ only: ['nowFunc'] })" class =" bg-gray-100 dark:bg-gray-800 border-gray-300 dark:border-gray-700 hover:opacity-90 border px-4 rounded py-1" >Reload router (only NowFunc)</button >
69
81
<button @click =" reloadRouter({ only: ['nowAlways'] })" class =" bg-gray-100 dark:bg-gray-800 border-gray-300 dark:border-gray-700 hover:opacity-90 border px-4 rounded py-1" >Reload router (only NowAlways)</button >
70
82
<button @click =" reloadRouter({ only: ['nowLazy'] })" class =" bg-gray-100 dark:bg-gray-800 border-gray-300 dark:border-gray-700 hover:opacity-90 border px-4 rounded py-1" >Reload router (only NowLazy)</button >
83
+ <button
84
+ @click =" reloadRouter({ only: ['nowLazyAsync'], onBefore: () => loadingNowLazyAsync = true, onFinish: () => loadingNowLazyAsync = false })"
85
+ class =" bg-gray-100 dark:bg-gray-800 border-gray-300 dark:border-gray-700 hover:opacity-90 border px-4 rounded py-1 flex items-center gap-2" >
86
+ <Spinner :visible =" loadingNowLazyAsync" class =" size-4" />
87
+ Reload router (only NowLazyAsync)
88
+ </button >
71
89
</div >
72
90
</div >
73
91
</template >
0 commit comments