Skip to content

Commit

Permalink
class 07
Browse files Browse the repository at this point in the history
  • Loading branch information
polashmahmud committed Aug 30, 2023
1 parent 414aae8 commit 297ac7b
Show file tree
Hide file tree
Showing 7 changed files with 183 additions and 7 deletions.
113 changes: 112 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"preview": "vite preview"
},
"dependencies": {
"vue": "^3.3.4"
"axios": "^1.5.0",
"vue": "^3.3.4",
"vue-router": "^4.2.4"
},
"devDependencies": {
"@vitejs/plugin-vue": "^4.2.3",
Expand Down
6 changes: 2 additions & 4 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
</script>

<template>
<div>
<h1 class="text-3xl font-bold underline">
Hello world!
</h1>
<div class="max-w-4xl mx-auto py-20 px-4 sm:px-6 lg:px-8">
<router-view/>
</div>
</template>
17 changes: 17 additions & 0 deletions src/api/usePosts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {ref} from "vue";
import axios from "axios";

export default function usePosts() {
const posts = ref([]);

const fetchPosts = async () => {
let response = await axios.get('/api/posts');

posts.value = response.data.data
}

return {
posts,
fetchPosts
}
}
6 changes: 5 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { createApp } from 'vue'
import './style.css'
import App from './App.vue'
import router from "./router/index.js";
import axios from "axios";

createApp(App).mount('#app')
axios.defaults.baseURL = 'http://localhost:8000';

createApp(App).use(router).mount('#app')
29 changes: 29 additions & 0 deletions src/pages/Home.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<script setup>
import {onMounted} from "vue";
import usePosts from "../api/usePosts.js";
const {posts, fetchPosts} = usePosts()
onMounted(fetchPosts)
</script>

<template>
<div class="space-y-16">
<div
v-for="post in posts"
:key="post.uuid"
>
<a href="" class="block">
<h1 class="text-3xl sm:text-4xl leading-10 font-extrabold tracking-tight text-gray-900">{{ post.title }}</h1>
<p class="mt-6 text-gray-500">
{{ post.teaser }}
</p>
</a>
</div>
</div>
</template>

<style scoped>
</style>
15 changes: 15 additions & 0 deletions src/router/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { createRouter, createWebHistory } from "vue-router";
import Home from "../pages/Home.vue";

const routes = [
{
path: '/',
name: 'home',
component: Home
}
]

export default createRouter({
history: createWebHistory(),
routes
})

0 comments on commit 297ac7b

Please sign in to comment.