updated lists index to use typescript and composition api

This commit is contained in:
Edward Tirado Jr 2025-04-06 17:30:14 -05:00
parent e335601ab8
commit d339424e7a
3 changed files with 34 additions and 29 deletions

View file

@ -13,30 +13,32 @@
</div>
</template>
<script>
export default {
name: "index",
data: () => ({
lists: [],
}),
methods: {
getLists: function () {
let config = useRuntimeConfig();
fetch(`${config.public.apiURL}/lists`, {
method: "GET",
headers: {"Content-type": "application/json"}
})
.then(response => response.json())
.then(json => this.lists = json)
.catch(err => console.log(err))
<script lang="ts" setup>
import type { MovieList } from "~/types/movielist";
const lists = defineModel<MovieList[]>("movie_list", { default: [] });
const updateLists = async function () {
let config = useRuntimeConfig();
const { data, status, error } = await useFetch<MovieList[]>(
`${config.public.apiURL}/lists`,
{
method: "GET",
headers: { "Content-type": "application/json" },
},
},
mounted() {
this.getLists()
);
if (error) {
if (error.value?.statusCode === 401) {
console.log("unauthorized");
}
} else {
lists.value = data.value || [];
}
}
};
onMounted(() => {
updateLists();
});
</script>
<style scoped>
</style>
<style scoped></style>