<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Alex Lomas on Medium]]></title>
        <description><![CDATA[Stories by Alex Lomas on Medium]]></description>
        <link>https://medium.com/@alexjlomas93?source=rss-41c96f375933------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*mkf_FgBROJFrZxZ2LskcYg.png</url>
            <title>Stories by Alex Lomas on Medium</title>
            <link>https://medium.com/@alexjlomas93?source=rss-41c96f375933------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 19:12:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@alexjlomas93/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Nuxt.js - A Different Way to Vue WordPress]]></title>
            <link>https://medium.com/propeller-engine-room/nuxt-js-a-different-way-to-vue-wordpress-bb3d5655db70?source=rss-41c96f375933------2</link>
            <guid isPermaLink="false">https://medium.com/p/bb3d5655db70</guid>
            <category><![CDATA[wordpress]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[nuxtjs]]></category>
            <dc:creator><![CDATA[Alex Lomas]]></dc:creator>
            <pubDate>Wed, 19 Jun 2019 15:25:26 GMT</pubDate>
            <atom:updated>2019-06-19T15:25:26.582Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0iU7yD6os7dtZ4FzcE_maw.png" /></figure><p><em>Our experience building a Nuxt.js application with headless WordPress</em></p><p>At Propeller Digital we work with amazing clients every day to deliver cutting-edge user experiences. As part of our ethos, we strive to embrace the latest technologies and have a lot of fun doing so.</p><p>The project this time was to prototype a headless WordPress application using either React or Vue.js, with the eventual goal being to compare it against our current WordPress setup and weigh up the pros and cons.</p><p>As a Frontend Developer, the prospect of dropping PHP and instead using an entirely JavaScript frontend was like a dream come true. Having worked previously with several frontend JavaScript frameworks such as Angular, Knockout, and React, it was Vue.js that was ultimately chosen. It scratched my intellectual itch to learn and try something new, whilst also having a lot of positive buzz in the industry.</p><p>It was important to me to maintain the level of reusable components and dynamism we currently offer in our WordPress setup, and Vue.js — or more precisely Nuxt.js — seemed up to the task.</p><h3>Why Nuxt.js over Vue.js?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FdjiesZktvJSMLNuwb6jwA.png" /></figure><p>It wasn’t a difficult decision. Nuxt.js, as a framework, takes and builds upon Vue.js, offering server-side rendering and SEO benefits out of the box. Performance and discoverability are often key must-haves from a client perspective, so it was very welcome having Nuxt.js take care of this with little to no extra setup.</p><h3>Our Setup</h3><p>With the scene set, let’s get into the meat of it.</p><p>One of specifications of this project was to incorporate headless WordPress. De-coupling the frontend from the backend has a myriad of well-documented benefits, including being able to serve multiple applications from one CMS, as well as protection for the frontend if the backend fails, to name a few.</p><p>Being API driven, we wrote several custom endpoints and utilised the following third-party plugins to expose the data we needed in the WP-JSON:</p><ul><li>Advanced Custom Field PRO: An essential plugin to create dynamic layouts with easy content entry.</li><li>ACF to REST API: Used to expose our ACF layouts to the WP-JSON for our Nuxt.js application to use.</li><li>WP REST API Cache: As the name suggests, to cache API requests in order to reduce the wait for data on the frontend. We implemented the suggested <em>save_post</em> hook in order to have the cache clear upon saving, ensuring our application was always up-to-date.</li></ul><p>On the Nuxt.js side, we integrated several workflow improvements such as <em>sass-loader </em>and<em> nuxt-sass-resources-loader </em>to use SASS and expose our mixins and SASS variables at a component level.</p><p>We also extended the routes. Out of the box, Nuxt.js utilises a pages directory for routing, with <em>index.vue</em> being the frontpage and <em>_id.vue</em> or subdirectories acting as subsequent pages. We found this structure, for the most part, led to unnecessary duplication of code. We wanted to adhere closer to the WordPress template hierarchy by creating reusable page templates instead, so we ended up extending the routing inside <em>nuxt.config.js</em> to point to either a <em>index.vue</em>, <em>archive.vue</em>, or<em> single-post.vue </em>file depending on the structure of the URL:</p><pre>router: {<br>    extendRoutes(routes) {<br>        for (let key in config.customPostTypes) {<br>            // Single Post Template<br>            if (config.customPostTypes[key].hasSinglePost) {<br>                routes.push({<br>                    name: config.customPostTypes[key].name + &#39;-single-post&#39;,<br>                    path: &#39;/&#39; + key + &#39;/:id&#39;,<br>                    component: &#39;src/pages/single-post.vue&#39;<br>                });<br>            }<br>            // Archive Template<br>            if (config.customPostTypes[key].hasArchive) {<br>                routes.push({<br>                    name: config.customPostTypes[key].name + &#39;-archive&#39;,<br>                    path: &#39;/&#39; + key,<br>                    component: &#39;src/pages/archive.vue&#39;,<br>                    chunkName: &#39;pages/&#39; + key,<br>                });<br>            }<br>        }<br>        // Page Template<br>        routes.push({<br>            name: &#39;page&#39;,<br>            path: &#39;/:id&#39;,<br>            component: &#39;src/pages/index.vue&#39;<br>        });<br>    }<br>}</pre><p>When any of these page templates are routed to, an action is dispatched to the Vuex store along with the slug, where it hits the WordPress API and refreshes the page data.</p><p>The benefit of this is that we wouldn’t need to create a new .vue file for each custom post archive, etc. Unless the design and functionality dictated it.</p><h3>Data Handling and Dynamic Layouts</h3><p>Expanding upon the aforementioned, all of our application’s API handling is carried out through actions and mutations to the Vuex store. Take our application’s home page as an example. When this page is visited it calls the following endpoint: <em>/wp-json/wp/v2/pages/?slug=home</em> fetching the ACF layout data we have exposed using the ACF to REST API plugin:</p><pre>[<br>   {<br>      ...<br>      &quot;acf&quot;:{<br>         &quot;components&quot;:[<br>            {<br>               &quot;acf_fc_layout&quot;:&quot;Title&quot;,<br>               &quot;text&quot;:&quot;This is a title component&quot;<br>            },<br>            {<br>               &quot;acf_fc_layout&quot;:&quot;Copy&quot;,<br>               &quot;text&quot;:&quot;This is a copy component&quot;<br>            }<br>         ]<br>      },<br>      ...<br>   }<br>]</pre><p>Our ACF data is made accessible in our page templates through the store where it is iterated over to create a special ACF component:</p><pre>&lt;ACF v-for=&quot;(component, index) in $store.state.pageData.acf.components&quot; :key=&quot;index&quot; :data=&quot;component&quot;&gt;&lt;/ACF&gt;</pre><p>This component is short and sweet but works as an intermediary to load in a dynamic component:</p><pre>&lt;template&gt;<br>    &lt;component :is=&quot;getComponent&quot; :data=&quot;data&quot;/&gt;<br>&lt;/template&gt;<br>&lt;script&gt;<br>export default {<br>    props: [<br>        &#39;data&#39;,<br>    ],<br>    computed: {<br>        getComponent() {<br>            return () =&gt; import(`../${this.data.acf_fc_layout}.vue`);<br>        },<br>    },<br>};<br>&lt;/script&gt;</pre><p>So, using the above JSON as an example, our index.vue would now have rendered a Title.vue and Copy.vue component. If we wanted we could add another Title component or a different component all together in the WordPress backend and it would display on the page. The only work needed is to ensure there is a corresponding .vue file created for any ACF components you setup (case sensitive). It is that simple.</p><p>This approach keeps both the backend data structure and frontend component driven with a high level of reusability. Once setup, it is easy to develop in and to expand. It also gives admins autonomy over page layouts without the need to create new templates. Win win.</p><h3>Final Thoughts</h3><p>As a prototype, working with Nuxt.js to create a headless WordPress application was a success. As a frontend framework it handled the functionality of our of current PHP setup with a lot of additional benefits. It was more compact and great to develop in. It is certainly no lie when they say it is adoptable and easy to pick up.</p><p>From a Propeller Digital perspective, there is code to refactor and more features we want to add to it; but, this prototype holds promise that we can use Nuxt.js in production at some point in the near future.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bb3d5655db70" width="1" height="1" alt=""><hr><p><a href="https://medium.com/propeller-engine-room/nuxt-js-a-different-way-to-vue-wordpress-bb3d5655db70">Nuxt.js - A Different Way to Vue WordPress</a> was originally published in <a href="https://medium.com/propeller-engine-room">Propeller Engine Room</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>