feat: back hook

This commit is contained in:
Rogee
2024-09-24 13:08:53 +08:00
parent 88befecac8
commit 51f193b627
2 changed files with 12 additions and 5 deletions

View File

@@ -15,7 +15,7 @@
import ListItem from "@/components/ListItem.vue";
import { getChannel } from "@/services/channels";
import { getChannelMessages } from "@/services/messages";
import { nextTick, onMounted, ref } from "vue";
import { nextTick, onMounted, ref, watch } from "vue";
import { useRoute, useRouter } from "vue-router";
const route = useRoute();
@@ -49,7 +49,8 @@ const loadMore = async () => {
});
}
onMounted(async () => {
const loadData = async () => {
// get channel info
channel.value = await getChannel(route.params.channel);
console.log("channel", channel.value);
@@ -57,5 +58,8 @@ onMounted(async () => {
// get channel messages
messages.value = await getChannelMessages(route.params.channel, { offset: route.params.offset });
console.log("messages", messages.value);
});
}
watch(route, loadData);
onMounted(loadData);
</script>

View File

@@ -47,7 +47,10 @@ const loadMore = async () => {
});
}
onMounted(async () => {
const loadData = async () => {
messages.value = await getFavoriteMessages({ offset: route.params.offset });
});
}
watch(route, loadData);
onMounted(loadData);
</script>