Using live preview with Payload CMS with Vue

I am trying to incorporate live preview with my Payload CMS, using Vue 3 as front end. I have followed this “tutorial” starting at around 11:00 but this CMS is usually more geared towards React.

I have set up this super simple Pages.js collections:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>const Pages = {
admin: {
useAsTitle: 'title',
livePreview:{
url: 'http://localhost:1234',
}
},
}
export default Pages
</code>
<code>const Pages = { admin: { useAsTitle: 'title', livePreview:{ url: 'http://localhost:1234', } }, } export default Pages </code>
const Pages = {
  admin: {
    useAsTitle: 'title',
    livePreview:{
      url: 'http://localhost:1234',
    }
  },
}
export default Pages

And I now want to connect it to Vue somehow I guess. I have my router index.js file which loads the Page component:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import { createRouter, createWebHistory } from 'vue-router'
import Page from '../views/Page.vue'
const routes = [
{
path: '/:slug',
name: 'Page',
component: Page,
props: true
}
]
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
routes
})
export default router
</code>
<code>import { createRouter, createWebHistory } from 'vue-router' import Page from '../views/Page.vue' const routes = [ { path: '/:slug', name: 'Page', component: Page, props: true } ] const router = createRouter({ history: createWebHistory(import.meta.env.BASE_URL), routes }) export default router </code>
import { createRouter, createWebHistory } from 'vue-router'
import Page from '../views/Page.vue'

const routes = [
  {
    path: '/:slug', 
    name: 'Page',
    component: Page,
    props: true
  }
]

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes
})

export default router

And the page component itself is pretty simple at the moment since I only offer one block type “Hero” block:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><template>
<div v-if="pageData">
<div v-for="block in pageData.layout" :key="block.id">
<hero-block v-if="block.blockType === 'hero'" :title="block.title" :subtitle="block.content[0]?.children[0]?.text" :imageURL="block.media?.url" :imageAlt="block.media?.['alt text']"></hero-block>
</div>
</div>
<div v-else>
<p>Loading...</p>
</div>
</template>
<script>
import HeroBlock from '../blocks/HeroBlock.vue'
export default {
name: 'Page',
components:{
HeroBlock
},
props: {
slug: {
type: String,
required: true
}
},
data() {
return {
pageData: null
}
},
async mounted() {
await this.fetchPageData();
},
methods: {
async fetchPageData() {
try {
const apiUrl = import.meta.env.VITE_API_URL;
const response = await fetch(`${apiUrl}/pages?where[slug][equals]=${this.slug}`);
if (!response.ok) {
throw new Error('Network response was not ok');
}
const data = await response.json();
this.pageData = data.docs[0];
if (!this.pageData) {
console.error('pageData is missing, load 404 here instead');
}
} catch (error) {
console.error('Error fetching page data:', error);
}
},
}
}
</script>
</code>
<code><template> <div v-if="pageData"> <div v-for="block in pageData.layout" :key="block.id"> <hero-block v-if="block.blockType === 'hero'" :title="block.title" :subtitle="block.content[0]?.children[0]?.text" :imageURL="block.media?.url" :imageAlt="block.media?.['alt text']"></hero-block> </div> </div> <div v-else> <p>Loading...</p> </div> </template> <script> import HeroBlock from '../blocks/HeroBlock.vue' export default { name: 'Page', components:{ HeroBlock }, props: { slug: { type: String, required: true } }, data() { return { pageData: null } }, async mounted() { await this.fetchPageData(); }, methods: { async fetchPageData() { try { const apiUrl = import.meta.env.VITE_API_URL; const response = await fetch(`${apiUrl}/pages?where[slug][equals]=${this.slug}`); if (!response.ok) { throw new Error('Network response was not ok'); } const data = await response.json(); this.pageData = data.docs[0]; if (!this.pageData) { console.error('pageData is missing, load 404 here instead'); } } catch (error) { console.error('Error fetching page data:', error); } }, } } </script> </code>
<template>
  <div v-if="pageData">
    <div v-for="block in pageData.layout" :key="block.id">
      
      <hero-block v-if="block.blockType === 'hero'" :title="block.title" :subtitle="block.content[0]?.children[0]?.text" :imageURL="block.media?.url" :imageAlt="block.media?.['alt text']"></hero-block>

    </div>
  </div>
  <div v-else>
    <p>Loading...</p>
  </div>
</template>

<script>
import HeroBlock from '../blocks/HeroBlock.vue'

export default {
  name: 'Page',
  components:{
    HeroBlock
  },
  props: {
    slug: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      pageData: null
    }
  },
  async mounted() {
    await this.fetchPageData();
  },
  methods: {
    async fetchPageData() {
      try {
        const apiUrl = import.meta.env.VITE_API_URL;
        const response = await fetch(`${apiUrl}/pages?where[slug][equals]=${this.slug}`);
        if (!response.ok) {
          throw new Error('Network response was not ok');
        }
        const data = await response.json();
        this.pageData = data.docs[0];

        if (!this.pageData) {
          console.error('pageData is missing, load 404 here instead');
        }
      } catch (error) {
        console.error('Error fetching page data:', error);
      }
    },
  }
}
</script>

So I have two questions:

1. How can I incorporate the live preview functionality with Vue 3 as front end framework?

2. Since Payload seems pretty into React, should I consider another CMS? People in their discord thought I could still use it, but are there other good open source headless CMS:s that are more “Vue friendly”?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật