-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
242 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 34 additions & 33 deletions
67
codesandbox@3/02-client/02-use-watcher/svelte-search.en.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,34 @@ | ||
<script> | ||
import { writable } from 'svelte/store'; | ||
//Create method instance | ||
const filterTodoList = userId => { | ||
return alovaInstance.Get(`/users/${userId}/todos`); | ||
}; | ||
const userId = writable(0); | ||
const { loading, data, error } = useWatcher( | ||
// Parameters must be set to functions that return method instances | ||
() => filterTodoList($userId), | ||
// The monitored status array, these status changes will trigger a request | ||
[userId] | ||
); | ||
</script> | ||
|
||
<select bind:value="{$userId}"> | ||
<option value="{1}">User 1</option> | ||
<option value="{2}">User 2</option> | ||
<option value="{3}">User 3</option> | ||
</select> | ||
|
||
<!-- Render the filtered todo list --> | ||
{#if $loading} | ||
<div>Loading...</div> | ||
{:else} | ||
<ul> | ||
{#each $data as todo} | ||
<li class="todo-title">{{ todo.completed ? '(Completed)' : '' }}{{ todo.title }}</li> | ||
{/each} | ||
</ul> | ||
{/if} | ||
<script> | ||
import { writable } from 'svelte/store'; | ||
import { useWatcher } from 'alova/client'; | ||
//Create method instance | ||
const filterTodoList = userId => { | ||
return alovaInstance.Get(`/users/${userId}/todos`); | ||
}; | ||
const userId = writable(0); | ||
const { loading, data, error } = useWatcher( | ||
// Parameters must be set to functions that return method instances | ||
() => filterTodoList($userId), | ||
// The monitored status array, these status changes will trigger a request | ||
[userId] | ||
); | ||
</script> | ||
|
||
<select bind:value="{$userId}"> | ||
<option value="{1}">User 1</option> | ||
<option value="{2}">User 2</option> | ||
<option value="{3}">User 3</option> | ||
</select> | ||
|
||
<!-- Render the filtered todo list --> | ||
{#if $loading} | ||
<div>Loading...</div> | ||
{:else} | ||
<ul> | ||
{#each $data as todo} | ||
<li class="todo-title">{{ todo.completed ? '(Completed)' : '' }}{{ todo.title }}</li> | ||
{/each} | ||
</ul> | ||
{/if} |
67 changes: 34 additions & 33 deletions
67
codesandbox@3/02-client/02-use-watcher/svelte-search.zh.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,34 @@ | ||
<script> | ||
import { writable } from 'svelte/store'; | ||
// 创建method实例 | ||
const filterTodoList = userId => { | ||
return alovaInstance.Get(`/users/${userId}/todos`); | ||
}; | ||
const userId = writable(0); | ||
const { loading, data, error } = useWatcher( | ||
// 参数必须设置为返回method实例的函数 | ||
() => filterTodoList($userId), | ||
// 被监听的状态数组,这些状态变化将会触发一次请求 | ||
[userId] | ||
); | ||
</script> | ||
|
||
<select bind:value="{$userId}"> | ||
<option value="{1}">User 1</option> | ||
<option value="{2}">User 2</option> | ||
<option value="{3}">User 3</option> | ||
</select> | ||
|
||
<!-- 渲染筛选后的todo列表 --> | ||
{#if $loading} | ||
<div>Loading...</div> | ||
{:else} | ||
<ul> | ||
{#each $data as todo} | ||
<li class="todo-title">{{ todo.completed ? '(Completed)' : '' }}{{ todo.title }}</li> | ||
{/each} | ||
</ul> | ||
{/if} | ||
<script> | ||
import { writable } from 'svelte/store'; | ||
import { useWatcher } from 'alova/client'; | ||
// 创建method实例 | ||
const filterTodoList = userId => { | ||
return alovaInstance.Get(`/users/${userId}/todos`); | ||
}; | ||
const userId = writable(0); | ||
const { loading, data, error } = useWatcher( | ||
// 参数必须设置为返回method实例的函数 | ||
() => filterTodoList($userId), | ||
// 被监听的状态数组,这些状态变化将会触发一次请求 | ||
[userId] | ||
); | ||
</script> | ||
|
||
<select bind:value="{$userId}"> | ||
<option value="{1}">User 1</option> | ||
<option value="{2}">User 2</option> | ||
<option value="{3}">User 3</option> | ||
</select> | ||
|
||
<!-- 渲染筛选后的todo列表 --> | ||
{#if $loading} | ||
<div>Loading...</div> | ||
{:else} | ||
<ul> | ||
{#each $data as todo} | ||
<li class="todo-title">{{ todo.completed ? '(Completed)' : '' }}{{ todo.title }}</li> | ||
{/each} | ||
</ul> | ||
{/if} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.