-
Notifications
You must be signed in to change notification settings - Fork 0
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
Shelly
committed
Oct 6, 2023
1 parent
fe8ba71
commit 397b30f
Showing
6 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import axios from 'axios'; | ||
|
||
export default { | ||
async getUser() { | ||
try { | ||
const response = await axios.get('/user?ID=12345'); | ||
console.log(response); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
} | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<template> | ||
<div class="container"> | ||
<h1 class="mb-4">UseMemoize範例</h1> | ||
<hr /> | ||
<div class="flex mt-4"> | ||
<button @click="getData(1)">獲取數據1</button> | ||
<button @click="getData(2)">獲取數據2</button> | ||
</div> | ||
<div class="mt-4"> | ||
{{ data }} | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
import { ref } from 'vue'; | ||
import { useMemoize } from '@vueuse/core'; | ||
import axios from 'axios'; | ||
const data = ref(null); | ||
const getUseMemoizeData = useMemoize(async id => { | ||
const url = `https://jsonplaceholder.typicode.com/todos/${id}`; | ||
const { data } = await axios.get(url); | ||
return data; | ||
}); | ||
const getData = async id => { | ||
await getUseMemoizeData(id).then(res => { | ||
data.value = res; | ||
}); | ||
}; | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
button { | ||
@apply border border-green-500 block m-2 bg-white p-2; | ||
} | ||
</style> |