Skip to content

Instantly share code, notes, and snippets.

View simonjcarr's full-sized avatar

Simon Carr simonjcarr

  • Gravity Software
  • Preston, Lancashire
View GitHub Profile
<template>
<div>
<div class="text-4xl font-bold">{{ post.title }}</div>
<div>{{ post.body }}</div>
<div class="italic mt-4">
Author: <span class="text-red-500">{{ user.name }}</span>
</div>
</div>
</template>
<template>
<div class="mx-4 rounded bg-gray-400 shadow">
<div class="p-2">
<div class="font-bold">Latest Posts</div>
</div>
<div class="bg-white p-2 border-2 border-gray-400 ">
<div v-for="post in recentPosts" :key="post.id">
<div class="mb-2">
-
<router-link :key="`/post/${post.id}`" :to="`/post/${post.id}`">{{
<template>
<div class="text-4xl font-bold mb-4">My Blog Roll</div>
<div v-for="post in posts" :key="post.id">
<div class="bg-gray-200 mb-4 shadow p-2 rounded">
<div class="text-2xl font-semibold">
<router-link :to="`/post/${post.id}`">{{ post.title }}</router-link>
</div>
<div class="mt-2 bg-gray-400 p-2 text-gray-700 rounded">
{{ post.body }}
</div>
import { ref } from "vue";
export default function usePosts() {
let post = ref({});
let posts = ref([]);
let user = ref({});
function fetchPosts() {
fetch(`https://jsonplaceholder.typicode.com/posts`)
.then(response => response.json())
import { createRouter, createWebHistory } from "vue-router";
import Home from "../views/Home.vue";
import Post from "../components/blog/Post.vue";
const routes = [
{
path: "/",
name: "Home",
component: Home
},
{
<template>
<div class="bg-gray-500 flex flex-col min-h-screen">
<Header /><!-- //height 32 -->
<div class="flex-1 flex w-2/3 mx-auto p-4 text-lg bg-white h-full shadow-lg">
<div class="w-3/5">
<router-view :key="$route.fullPath" />
</div>
<div class="w-2/5">
<LatestPosts />
</div>
<template>
<div class="home">
<BlogRoll />
</div>
</template>
<script>
import BlogRoll from '@/components/blog/BlogRoll.vue'
export default {
name: "Home",
<template>
<div class="mx-4 rounded bg-gray-400 shadow">
<div class="p-2">
<div class="font-bold">Latest Posts</div>
</div>
<div class="bg-white p-2 border-2 border-gray-400 ">
<div v-for="post in posts" :key="post.id">
<div class="mb-2">- <router-link :key="`/post/${post.id}`" :to="`/post/${post.id}`">{{ post.title }}</router-link></div>
</div>
</div>
<template>
<div class="text-4xl font-bold mb-4">My Blog Roll</div>
<div v-for="post in posts" :key="post.id">
<div class="bg-gray-200 mb-4 shadow p-2 rounded">
<div class="text-2xl font-semibold"><router-link :to="`/post/${post.id}`">{{ post.title }}</router-link></div>
<div class="mt-2 bg-gray-400 p-2 text-gray-700 rounded">{{ post.body }}</div>
</div>
</div>
</template>
<template>
<div class="bg-gray-500 flex flex-col min-h-screen">
<Header />
<div class="flex-1 flex w-2/3 mx-auto p-4 text-lg bg-white h-full shadow-lg">
<div class="w-3/5">
<router-view :key="$route.fullPath" />
</div>
</div>
</div>
</template>