Markus Oberlehner

Articles about JavaScript

Using Testing Library jest-dom with Vitest

Vite brought super fast bundling and hot reloading to our regular dev workflow, and Vitest is doing the same for our testing workflow. So I'm mostly transitioning away from Jest in favor of Vitest. But there are a lot of amazing tools in the Jest ecosystem, and not of them can be easily replaced. Luckily, the Vitest API is mostly compatible with the Jest API...

Using Mock Service Worker with Vitest and fetch

The JavaScript ecosystem has a lot to offer when it comes to testing. With the recent addition of Vitest we get the performance and convenience features of Vite for testing too. Mock Service Worker is an excellent mocking solution for mocking network requests in the browser and Node.js...

Vue Project Directory Structure: Keep It Flat or Group by Domain

When starting a new project or refactoring an existing one, the question often arises: how to set up the project's directory structure. My first advice is to keep the folder hierarchy as flat as possible for as long as possible. But depending on the size of our project, there might be a time where we feel the need to add additional folders to organize our Vue components and other files...

Vue Composition API: VueUse Composable Library

The Composition API makes it very easy to share code between components in our codebase or even across projects via npm packages. I recently stumbled upon the excellent VueUse library that provides us with a ton of valuable composables. In this article, we take a closer look at some of the most interesting ones...

Vue Composition API: Composables

What makes the Vue 3 Composition API so much better than the Options API is code sharing. Inside the setup hook of a component, we can group parts of our code by logical concern. We then can extract pieces of reactive logic and share the code with other components...

Cypress Live-Reload Tests on Code Changes

Out of the box, Cypress offers an amazing live-reloading feature. But there is one caveat: live-reloading only works when changing test code, not when updating the application code. Nowadays, we are used to live-reloading in the browser thanks to webpack hot module replacement (HMR) and other fantastic development tools like Vite or Snowpack. If we had something similar in Cypress, practicing TDD would be a lot easier...

Decoupling Component Tests From Implementation Details with Preconditions

When testing components (e.g., Vue or React) or regular JavaScript modules, we typically want to decouple our test code from the implementation as much as possible. Ideally, we want to write black box tests. That means that we are only allowed to interact with the public API of the component under test...

Vue 3 Composition API vs. Options API

When migrating from Vue 2 to Vue 3 or starting a new Vue 3 project, many people wonder if they should continue using the Options API or go all-in on the Composition API. I advise using the Composition API (for new components) exclusively ASAP and never looking back...

Vue 3 Composition API: ref() vs. reactive()

One of the first questions that arise when starting with the new Vue Composition API is ref() or reactive()? The initial instinct is to use ref() for primitives (Boolean, String,...) and reactive() for objects. But there is more to it...

Premium Vue and Nuxt Templates for Web Apps and Sites

Suppose you're searching for high-quality Vue.js templates, I recommend you to take a look at the work of Creative Tim. In this article, I'll show you a list of handpicked premium templates to build Web Applications or Websites with Vue.js and Nuxt.js...

Events and Callbacks: Parent/Child Component Communication in Vue

Props Down / Events Up is the standard paradigm for communication between parent and child components in Vue.js. React, on the other hand, uses callback functions instead of events. But why is using callbacks considered an anti-pattern in the Vue.js world? And what are the conceptual differences...

Building Vue.js Applications Without webpack

In the good old times, creating a JavaScript-enhanced website was straightforward: create a .html file, add a <script> tag, write some JavaScript, and open the file in the browser. Nowadays, building web applications requires complex build toolchains, a node_modules directory with gigabytes of dependencies, and a complicated webpack configuration file...

JavaScript Runtime Bundling Concept

Imagine a world where you don't need to install a single dependency, but you're still able to use all modern JavaScript features. Where you don't need to run a build script every time you change a file. And you can do all of that knowing that your app will be perfectly minified and optimized for old browsers on production...

Group, Extract, Share: Working with the Vue Composition API

One problem with the Vue Options API is that it is hard to share stateful logic that relies on reactive variables. The Composition API offers us an excellent solution to this problem. In this article, we look at a possible workflow for efficiently building components and applications with Vue 3 and the Composition API...

watch vs. watchEffect when to use what with Vue.js

When I first studied the new Composition API, I was confused that there are two watch hooks: `watch()` and `watchEffect()`. From the documentation alone, it was not immediately apparent to me what's the difference...

Partial Hydration Concepts: Lazy and Active

I am currently working on porting vue-lazy-hydration to Vue 3. With that comes the potential to make some significant improvements since Vue 3 has an API that allows controlling the hydration of VNodes. Working with the new APIs got me thinking about the general concept of hydration...

Vue.js Feature Toggle Context Provider

Some time ago, I read a very informative article by Pete Hodgson about feature toggles. I'm thinking a lot about the Context Provider Pattern and the types of problems it can help solve, and it appeared to me as if feature toggles are one of the use cases where this pattern can provide a lot of o value...

useState and useReducer with the Vue 3 Composition API

In the React world, React Hooks are basically what in the Vue world is the Composition API. Although React Hooks and the Vue Composition API try to solve similar problems (mainly, reusability of stateful logic), how those two frameworks deal with reactivity under the hood is quite different...

Application State Management with Vue 3

With the new Composition API and Vue 3, there is a lot of talk about whether or not we still need Vuex or if it is possible to replace Vuex completely by making reactive objects globally available. In this article, I argue that thanks to the Composition API's new tools, Vuex is rarely necessary anymore...

Wrap Third-Party Libraries

Certain coding practices seem superfluous when you first encounter them, but sooner rather than later you get into a situation where you wish you had stuck with them. Wrapping third-party libraries instead of using them directly in your codebase is one of those practices...

Vue.js Style Provider Pattern

I recently played around with the idea of using renderless provider components not only for data but for styles too. This pattern seems especially promising when it comes to building base components with style modifier props...

Avoid Opaque Dependency Injection Techniques with Vue.js

We use Dependency Injection to achieve loose coupling. But loose coupling and Dependency Injection can make it harder to understand how our code works. It can make it more challenging to determine where a particular dependency is coming from...

Context-Aware Props in Vue.js Components

Recently I saw an interesting Tweet by Mark Dalgleish, about the idea of contextual defaults for React components. I was especially interested in this because I had to solve a similar problem only a few days before...

Tight Coupling vs. Loose Coupling in Vue.js

When talking about loose coupling and tight coupling, often, the impression arises that tight coupling is something we always have to avoid. But this is almost impossible. What's essential is that we use loose coupling when bridging the gap between layers of our application...

$refs and the Vue 3 Composition API

If you’re used to working with Vue 2 $refs and switch to the Vue 3 Composition API, you might wonder how to use $refs inside the new setup() method. In this article, we find out how to use the new ref() function as a replacement for static and dynamic HTML element references...

Telling a Story with Test Code

A few weeks ago, I wrote about naming unit tests BDD style using Given/When/Then. In this article, I have expressed the thought that I do not like to repeat information in the description and in the expect statement. After writing some tests the way I've described in this article, I noticed a couple of drawbacks...

Cut Your Nuxt.js generate Build Time in Half with context.payload

One of my freelancing projects is a Nuxt.js project powered by the headless CMS Storyblok. Because performance is critical, I decided to use Nuxt.js in generate mode outputs static HTML files for each page at build time. But because Nuxt.js needs to generate 1.000+ pages, the build time got long...

Building Partially Hydrated, Progressively Enhanced Static Websites with Isomorphic Preact and Eleventy

One of my top priorities is to create the fastest possible websites (think marketing sites, not web applications), but I also don't want to do without modern tools and a component-based workflow. While there are developments in the right direction, I don't think tools like Gatsby and Nuxt.js are quite there yet when it comes to building content heavy, mostly static sites...

Setting up Eleventy with Preact and htm

One of my top priorities is to create the fastest possible websites (think marketing sites, not web applications), but I also don't want to do without modern tools and a component-based workflow. While there are developments in the right direction, I don't think tools like Gatsby and Nuxt.js are quite there yet when it comes to building content heavy, mostly static sites...

Naming Your Unit Tests: It Should vs. Given/When/Then

For the most time, when writing unit tests, I favored the it should ... pattern for naming my tests. But time and time again, I noticed that when following this naming convention, I either had to write very long test cases or omit important information...

Vue.js Functional Base Components Powered by CSS Modules

In one of my earlier articles, I wrote about how to use functional Vue.js components so that they inherit attributes such as classes and styles. This way, functional components are perfect for creating simple base components. In this article, we take a look at how we can simplify and generalize the process of creating new functional base components by automatically creating new Vue.js components from CSS files...

Lazy Resolving Observable API Services with Vue.js

Although GraphQL is pretty cool and powerful, I also like the simplicity of good old REST API endpoints. Also, we often can't use GraphQL for everything because there is no GraphQL endpoint available. In this article, we take a closer look at how we can replicate one of the core features of GraphQL, which makes it possible only to load what is absolutely necessary, in a classic REST API-based application...

Vuex Data Model and Feature Module Strategy Part 2: Feature Modules

In this article, we extend the functionality of our very simple demo application from the previous article to display multiple paginated lists for the same content type. The paginated list feature module does not fetch any data itself but instead connects to the data model module. Doing so makes it possible to cache requests with the same query across feature modules to reduce the number of requests to your API and make your app feel snappy...

Vuex Data Model and Feature Module Strategy Part 1: The Data Model Module

The data model approach builds on the idea that you have a separate Vuex module for every data model of your application (e.g., users, posts, comments). Following this pattern makes it very straightforward to structure your Vuex store. But there are also some problems with a pure data model paradigm...

Thoughts about Utility-First CSS Frameworks

Many people, including me, are very skeptical about the utility-first approach of Tailwind CSS and other similar CSS frameworks like Tachyons. But I think it is essential to be open-minded about new ideas and techniques, especially if many people like it...

Reusable Functional Vue.js Components with Tailwind CSS

Tailwind is a CSS framework that I never used extensively, but I always found it interesting enough to keep it on my radar and occasionally play around with it. Today we explore how we can use Tailwind CSS with Vue.js. In this article, we identify potential pitfalls when using utility-first CSS frameworks and how to avoid them. Most importantly, we find out how to use Vue.js functional components to create abstractions for repeating patterns like cards and headlines...

Setting up Tailwind CSS v2 with Vue.js

Tailwind CSS is one of the rising stars in the CSS framework world. It's especially popular in the Laravel and Vue.js community. In this article, we learn how to set up Tailwind CSS to work with a Vue CLI powered application...

Simple Solution to Prevent Body Scrolling on iOS

In my last article about building accessible popup overlays with Vue.js we used a simple technique to prevent scrolling in the background. I think that this little trick for preventing scrolling on the `<body>` element on all devices, including iOS 12 and below (finally, this was fixed in iOS 13 🎉) is worth taking a closer look...

Scrolling Shadows with Vue.js

Sometimes we find ourselves in a situation where the content of a particular area of our website or web app is too big to fit inside of our layout. In such cases, overflow: auto can come in handy. But usually, this comes with the downside that users with browsers which do not show scrollbars by default (macOS or most mobile devices) might not be aware that it is possible to scroll...

Popup Overlays with Vue Router and Portal Vue

If we like it or not, modal dialogs and overlays are a recurring pattern on many websites and apps. In this article, we take a look at how to implement popup overlays with Vue Router so that they have a URL. We attach great importance to making our solution accessible so all of our users can use it without frustration. Also, we want to keep it simple but still create a reusable solution...

Dynamic Vue.js CRUD Applications

Often it seems like we build the same applications again and again. And at least sometimes it feels like that because indeed we do. Again and again, we build the same CRUD applications with their generic list views, edit forms, and previews. Throughout this article, we examine how to create a generic and reusable structure for a traditional CRUD application. Our primary goal is to keep our codebase DRY...

Decouple Vue.js components from the Vuex Store

One of the main concerns I have when building Vuex-based applications is the tight coupling of components with the Vuex store that seems inevitable when using Vuex. Ideally, I want to be able to switch the data layer of my application at any time without having to touch all my components that rely on data from an external resource...

Dependency Injection in Vue.js with Functional Component Factories

If you are a regular reader of my blog (thanks to all of you), you may have noticed that many of my articles are about decoupling components from their dependencies. Over the past few months I have written a few articles on this subject. But today I share with you an additional way to inject dependencies into Vue.js components that I find very interesting: dependerncy injection via functional components and component props...

Generic Content Vuex Modules

Today we look at how we can design a system for quickly creating generic Vuex modules for typical CRUD content types. Often when creating applications rather sooner than later we catch ourselves repeating the same boilerplate code over and over again because most of our content types are very similar at their core...

Make your Vuex State Flat: State Normalization with Vuex

Listening to one of Full Stack Radio's latest episodes, I was very impressed by the expertise of Matt Biilmann, CEO of Netlify. Adam Wathan and Matt talked a lot about how global state is handled in the Netlify web application. Although the Netlify app is built with React and Redux when he spoke of his philosophy for structuring the global state of the app, it motivated me to think a little more about this topic in the context of Vue.js and Vuex...

Controlling the LEGO Mindstorms NXT with Node.js Part 1: It's Alive

For several years now, my LEGO Mindstorms NXT has been living a life as a decorative item on my desk. Since I wasn't in the mood to do real work today, I was wondering if it wouldn't be possible to use JavaScript to control it. After searching the web I found out that it is actually possible to do this. So let's have some fun...

Vue.js Powered Data Model and Query Builder

I love the concept of reactive computed properties in Vue.js. So much so that I miss them in situations where I don't have them available. In this article, we will explore how to create reactive data models with all the features of regular Vue.js components such as computed properties...

Separation of Concerns Re-Revisited

The more I read about React Hooks and the RFC for the Vue.js Composition API, the more I think about the early days of modern frontend frameworks like React and Vue.js...

Vue.js Single File Component Factory

In my opinion, the best way to inject dependencies is via factory functions that take the dependencies as parameters. Unfortunately, it is not possible to export factory functions from Vue.js Single File Components. According to the specification, the default export should be a Vue.js component options object...

Accessible Custom Vue.js Select Component Part 2: Advanced

Today, we will follow the W3C guidelines, on how to build a collapsible dropdown, very closely, to create a solid custom form select Vue.js component that works well for both keyboard and screen reader users as well as people who use a mouse or their finger to browse the web...

Building Vue.js UI Components With HTML Semantics in Mind

When building modern, component-based client-side applications, we often tend to forget about the foundations of web development: HTML and CSS. Sometimes we act as if the rules of writing semantic HTML are somehow no longer relevant. But the opposite is true...

Working With Functional Vue.js Components

On my journey to find ways to improve the rendering performance of large scale Vue.js applications, I stumble upon functional components as a possible solution from time to time. But so far, I've always found one or two reasons why I can't use them in my application...

Multi Export Vue.js Single File Components With Proxy Exports

In one of my previous articles, we examined how we can use JSX in Vue.js to export multiple Vue.js components from a single Single File Component (SFC) .vue file. Just recently I found an even easier solution to this problem...

Build Decoupled Vue.js Applications with Hooks

Recently, I was wondering how best to decouple the code needed to track certain form submissions (e.g. conversion tracking in Google Analytics or Matomo) from the business logic of the forms...

Observable REST API with Vue.js

Just recently, I discovered a rather new feature in Vue.js: Vue.observable. It is used internally in Vue.js to make the object returned by the data() function of a component reactive. In this article, we take a look at how we can use this new feature to build a straightforward reactive polling system for a regular REST API...

Implementing the Builder Pattern in Vue.js Part 1: Listings

Recently I've seen a great talk by Jacob Schatz about Phenomenal Design Patterns in Vue. One of the patterns he mentioned in his talk was the Builder Pattern. I found his example very interesting, so it was clear to me that I had to experiment with this pattern myself...

The IoC Container Pattern with Vue.js

In this article we experiment with implementing the IoC container pattern in Vue.js. The IoC container pattern is prevalent in other languages and frameworks, but not so much in the JavaScript world – we also take a look at why that might be so...

try...catch: The Right Way

Because of a recent bug hunting session where it took me a couple of hours to drill down several levels of npm dependencies in order to finally find a try...catch statement with the catch part being empty, I decided to write an article about this topic. Although, I have to admit, my first instinct was to be angry at the developer who did this...

Dependency Injection in Vue.js Applications

I often wonder how to decouple certain parts of an application best. At first, this seems pretty straightforward in the context of Vue.js applications. You have components and components pass down properties and emit events that's it. Right? Yeah, kind of. But also kind of not...

Distributed Vue.js Applications Part 1: Loading Components via HTTP

Imagine the following scenario: We have a central content distribution server responsible for pushing new content (think of news articles, for example) to a variety of Vue.js-based client applications. But we not only want to push new content but also describe the shape of the content via Vue.js components...

Vue.js Error Handling with Renderless Components

Reliable error handling is one of those things which can make the difference between a good application and a great application. In today's article we'll take a look at how we can build renderless components to help us capture errors in our Vue.js applications...

Visual Regression Tests for Vue.Js Applications with Jest and Puppeteer

Assuming that we already have integration tests and unit tests in place, it’s time to take a look at how we can build our next line of defense against unwanted regressions in our app. In this article we'll use Jest and Puppeteer to set up Visual Regression Tests...

Renderless Vue.js Lifecycle Hook Components

Reusing logic and keeping your codebase DRY should be one of your top priorities. In a Vue.js application components are the most important means of code reuse. But usually we think of components as a combination of markup, logic and CSS. At first, it might not be very intuitive to use components to provide only logic and not render anything at all...

Integration Testing Vue.js Components With Jest and Puppeteer

This is a followup article of my previous article about Integration Testing Vue.js applications with Cypress. In this article, we test the same application but, instead of using Cypress, we want to use the combined forces of Jest and Puppeteer...

Integration Testing Vue.js Container Components With Cypress

In my previous article about Advanced Component Composition, we wrote Unit Tests for all of our Vue.js components except the Container Components. Writing Unit Tests for components with a lot of external dependencies (e.g. making API calls or accessing the $route object) is usually very hard to do because most of the time you have to mock a lot of their dependencies...

Container Components in Vue.js: Advanced Component Composition

When building large scale applications where it is a top priority to achieve high test coverage, you are often faced with the problem that it becomes very difficult to test some of the components of the application. A common reason for this is that you have to mock a lot of global dependencies like the Vue Router or the Vuex Store...

Reusing Logic With Renderless Vue.js Frame Components

Reusing logic and keeping your codebase DRY should be one of your top priorities. In a Vue.js application, components are the primary means of code reuse. But usually, we think of components as a combination of markup, logic, and CSS. At first, it might not be very intuitive to use components to provide only logic and not render anything at all...

Multi Export Vue.js Single File UI Components

In today's article we'll learn how to build Vue.js Single File Components (SFC) which export multiple components at once using ES6 named exports. Furthermore we'll utilize render functions to render the markup of our components via JSX. By combining these techniques, we are able to create UI components that consist of several separate components combined into a single file...

How to Use GraphQL with Vue Apollo Components and Netlify Functions

Although I've already experimented a little bit with GraphQL, especially how to integrate GraphQL in a Vuex powered application, I never took the time to delve into the details. In today's article we'll build a simple example application using Apollo Components...

Building a Renderless reCAPTCHA v3 Form Component with Vue.js

The modern frontend stack is all about reusable components. The renderless component pattern is one of the most elegant ways of how to build highly reusable components. Today we'll build a renderless component for handling form submission, loading and error logic in a generic and reusable way. Additionally we'll take a look at how we can use the new reCAPTCHA v3 to secure our form from spam submissions...

Lazy Load Vue.js Components When They Become Visible

Over the last couple of years as a web developer, I've seen the same pattern over and over again: the homepage becomes a political issue within a company because every department wants to present itself and, of course, every department considers itself the most important. Usually, two things happen: a slider is added at the top of the page so that each department can get its slide at the very top, and more and more stuff is added to the homepage...

Using the Google Maps API with Vue.js

In today's article, we take a look at how we can use the Google Maps API in combination with Vue.js. We build a simple Vue.js component, which renders a Google Map. Furthermore, we learn how to listen for click events on markers and how we can cluster multiple markers in close distance to each other...

abomination: a Concept for a Static HTML / Dynamic JavaScript Hybrid Application

Static site generators are on the rise. To be more specific: static site generators like Gatsby.js (React) and VuePress (Vue.js) which are based on modern frontend frameworks are becoming more and more popular. Although those are great projects and especially the developer experience is amazing, there is one huge downside of using those systems to generate mostly static, text and image based websites...

Using the Wrapper Factory Pattern for Vue.js Unit Testing

If you test Vue.js Components with a certain complexity, oftentimes you'll be faced with the situation of repeating the same component initialization code again and again. There are multiple patterns to deal with situations like that but today we'll take a look at how we can solve this problem by using a wrapper factory function...

Building a Static Site with Storyblok and Gridsome

In today's article we'll take a closer look at Gridsome and how it compares to the well established Nuxt.js. We will integrate the headless CMS Storyblok as a datasource for Gridsome an we'll build a simple site to demonstrate the capabilities of those systems...

Building a Simple Content Slider with Vue.js

Today we'll take a look at how we can build a simple content slider with Vue.js. We'll use the renderless component technique to create a reusable component which we then use to build multiple versions of a content slider...

Skeleton Loading Animation with Vue.js

Although there is some debate as to whether skeleton loading screens do enhance the perceived performance or not, there seems to be some evidence that they do work if they are done right. So today we'll take a look at how we can implement the skeleton loading animation pattern with Vue.js...

Using Location Data with Vue.js and Open Street Map

Today we'll explore how we can use the native browser geolocation API and the Open Street Map API to handle location data in a Vue.js applications. In our example app the users can press a button to automatically enter their address data into a form by allowing the geolocation API to access their current location...

Creating PDF Invoices with Airtable, Vue.js and Puppeteer

I recently started freelancing. After doing my thing, building great web stuff (of course), there comes a lot of additional work I'm not so experienced at: time tracking, book keeping and accounting...

Implementing a GDPR Consent Workflow with Vue.js

Love it or hate it, GDPR compliance is now a requirement if you want to collect data from EU citizens. Today we take a look at how we can use the concept of renderless components to implement a basic GDPR consent workflow...

Using Cloudinary and Storyblok to Handle Assets for a Vue.js Application

In this article we‘ll learn how we can combine the awesome digital asset management platform Cloudinary with the power of Storyblok to automatically handle image optimazation for us. We‘ll also explore how we can use the additional data, like the dominant color or the aspect ratio of an image, provided by the Storyblok Cloudinary Assets plugin, to implement enhanced image lazy loading...

Using Docker to run BackstopJS Powered Visual Regression Tests

My very own CSS framework avalanche, uses BackstopJS for regression testing. Unfortunately, for the most time, this didn't work as expected on my continuous integration service of choice: Travis CI. The rendering of fonts is slightly different on the Linux image which is used on Travis CI compared to macOS which I use for development...

Implementing a Simple Middleware with Vue Router

The concept of Middleware in frameworks like Laravel makes it fairly easy to do things like requiring an authenticated user for specific routes. Today we explore how we can implement a similar concept in the Vue.js world using the Vue Router...

Building a Simple Ken Burns Slider with Vue.js

Clients love them most web developers hate them: sliders with fancy transition effects. Today we’ll build a straightforward implementation of an image slider featuring the famous Ken Burns transition effect...

Automatic SPA FTP Deploys with CircleCI

Most of my articles are about the latest and greatest tools and technologies out there. One of the nice things about writing blog articles is that you can devote yourself fully to exploring new technologies. There is no client dictating the specifications, and there is no legacy code and technologies you need to consider...

Vue.js Responsive Image Lazy Loading

In today's article, we take a closer look at how we can build our own custom lazy loading image component with Vue.js. We use the fast and lightweight Lozad.js package for handling the lazy loading logic for us, and we enhance it with the ability to display the dominant color of the image as a fallback color...

Building a Website with Vue.js, the Storyblok Visual Editor and Netlify

In recent weeks I played around with a ton of headless content management systems. To cut a long story short: there are a lot of bad and a couple of pretty good ones out there. At the end of my journey, I was left with two systems I both very much enjoy: Contentful and Storyblok...

Building a Custom Storyblok Field Type Plugin With Vue.js

In recent weeks I played around with a ton of headless content management systems. To cut a long story short: there are a lot of bad and a couple of pretty good ones out there. At the end of my journey, I was left with two systems I both very much enjoy: Contentful and Storyblok...

Building a Pre-Rendered Website With Nuxt.js and Storyblok

In recent weeks I played around with a ton of headless content management systems. To cut a long story short: there are a lot of bad and a couple of pretty good ones out there. At the end of my journey, I was left with two systems I both very much enjoy: Contentful and Storyblok...

How to Pre-render Vue.js Powered Websites with webpack

In my recent article, we built a landing page type website powered by a headless CMS and Vue.js. We've seen how quickly we can build a simple site with these two technologies. However there is still a major problem with the result of our work: the loading performance is pretty terrible...

Building Landing Pages with Vue.js and a Headless CMS

Although, nowadays, my main focus at work is to build app like websites, at my former employer, I generally worked on brochure pages. We built a variety of small to medium scale websites powered by the PHP based CMS Drupal. A couple of days ago, I started thinking about how I would build such sites today...

Layouts with Vue.js - How to Create Dynamic Layout Components

Vue.js is flexible enough to serve as a tool for either progressively enhancing certain parts of traditional server-side rendered applications or powering large scale single-page applications, and everything in between. If you build complex single-page applications, you'll most likely encounter situations where you need different page layouts for certain parts of your app...

Vue Router Page Transitions with Fade, Slide and Zoom Effects

In my last article, we've explored how to use the powerful Vue.js transition component, to animate an element from zero height to auto height. Today we'll take a look at how we can utilize the transition component to create fancy transitions between different pages of a Vue Router powered Vue.js application...

Transition to Height Auto With Vue.js

Every now and then, I end up in a situation where I need to animate an HTML element from `height: 0` to its natural height (`height: auto`). Based on my experience, I already know that there are only three ways of achieving this: transitioning from `max-height: 0` to `max-height: Xpx`, transitioning from `transform: scaleY(0)` to `transform: scaleY(1)` and JavaScript magic...

Should I Store This Data in Vuex – When Should I use Vuex?

When first starting with Vuex, most people wonder what data should be stored in Vuex in the first place? In the journey of answering this question, for many people (including me) comes what I call the “Let's Store Everything in Vuex” phase. But very quickly, after having encountered the first obstacles, comes the realization that this cannot be the be-all and end-all solution to managing state in Vue.js applications...

Building Renderless Components to Handle CRUD Operations in Vue.js

In episode 81 of the Full Stack Radio podcast Adam Wathan and Evan You talked about the possibility of utilizing the power of slot scopes to build components which sole purpose is to fetch data and provide the result via slot scope properties to the markup. In today's article we're going to take this into practice and we even go a little further: we'll build “renderless components” to handle all CRUD operations in a reusable way...

Building Custom Multi-Option Form Components with Vue.js

In my opinion, one of the most significant features of Vue.js, is the ability to build custom form components with ease. Thanks to `v-model` and the straightforward event system, we can build powerful new form components or enhance existing form fields and input types with superpowers...

Replicating the Twitter Tweet Box with Vue.js

Today we will take a look at how to replicate the Twitter Tweet Box (the text area you use to compose new tweets) using Vue.js. At first glance, the Tweet text field might look like a straightforward `<textarea>` element, but it is not. It's certainly much more complicated than that. In this article, we'll find out why the Twitter Tweet Box isn't a simple `<textarea>` element and how the developers of Twitter have solved this problem. Furthermore, we'll explore a more convenient way, of how we can recreate the same functionality in Vue.js...

Visual Regression Testing with Nightwatch.js and Cucumber.js

As most of my regular readers have probably already noticed, I'm a huge fan of testing all the things. In many of my recent articles, we've already explored multiple techniques for unit testing and acceptance testing. Unit testing ensures that certain parts (or _units_) of our code do work correctly with acceptance testing, we can guarantee that what we've built does what it should do. Visual regression testing makes it possible that we can test if our application looks the way it's supposed to look...

Building a Date Input Component with Vue.js

Today we build a custom date input component powered by Vue.js. Although there is a native date input type available in all modern browsers, there are certain situations where the native date input field falls short. So let us take a look at how we can build a custom date input field with Vue.js...

Crazy Powerful Nightwatch.js Cucumber Step Definitions

Although testing, and especially acceptance testing, seems like a rather boring topic (at least to many developers) in the past few months I acquired an interest in optimizing the test setup and come up with better ways of writing tests. Especially when using Nightwatch.js in combination with Cucumber.js, there is another challenging aspect to it: writing step definitions...

Setting up a Vue.js Project with webpack 4 and Babel 7

For my previous article about three different ways of how to structure a Vue.js application, I wanted to set up a build system which not only allows for regular JavaScript code splitting, but also CSS code splitting. Thanks to webpack 4 and the mini-css-extract-plugin (which basically is the successor of the extract-text-webpack-plugin), CSS code splitting is finally possible...

Vue.js Application Structure and CSS Architecture

In recent days, I thought a lot about structuring large scale component-based applications. Oftentimes, at the beginning of a project, everything seems to be easy. You build a couple of components, put them together, and without too much effort you've implemented the first feature of your application in a reasonable amount of time...

Route Model Binding with Vue.js and Vuex

I'm currently in the process of refreshing my knowledge about Laravel. I do so by reading the official documentation. Although, I almost exclusively work on the front side of things with Vue.js nowadays, there is a lot to be learned by getting to know techniques outside of your comfort zone...

Network Stubs and Timers with Nightwatch.js and Cucumber.js

In my previous article about automated acceptance testing with Cypress I explored the possibilities of the `cy.route()` and `cy.clock()` commands. Because I fell in love with how easy it is to stub network requests and manipulate JavaScript timeout functions (like `setTimeout` and `setInterval`) with those two commands, I began to feel bad about not having this functionality in Nightwatch.js und Cucumber.js powered acceptance tests...

Automated Acceptance Testing with Cypress and Vue.js Part 1: Setup

In today's article, we're going to take a look at one of the rising stars in the automated end-to-end testing scene: Cypress. When I first discovered Cypress, I thought that it looks very promising, but I was skeptical if it can live up to the hype...

Dynamically Loading SVG Icons with Vue.js

In this article we're going to explore two approaches for dynamically loading SVG icons with Vue.js. We'll use the wonderful vue-svgicon package as a foundation for our SVG icon workflow...

How to Structure a Complex Vuex Store with Modules

In this article, we take a look at a possible way of how to structure a Vuex store for a large scale application. When I was researching possible approaches for handling the state of big, Vue powered applications with Vuex, it was pretty hard to find any good examples...

How to Handle Multi-row Forms with Vue, Vuex and vuex-map-fields

In one of my previous articles about form field handling in combination with Vuex, I introduced the vuex-map-fields package, which allows to conveniently map a list of fields to Vuex conform getter and setter functions. In today's article we take it a step further and we'll explore how we can use the latest release of vuex-map-fields to build a Vuex powered multi-row form...

Vue.js Form Validation with Vuelidate

In today's article, we build a simple contact form with inline validation powered by Vuelidate. One of the best features of Vuelidate is its relatively small footprint...

Combining GraphQL and Vuex

In today's article, we're going to take a look at how we can combine GraphQL and Vuex to manage the state of a Vue application. But first of all let me say that the way we're going to integrate the Apollo GraphQL client into our Vue application is not the “official” way of how to integrate GraphQL into a Vue powered application...

Two-Way Data Binding with v-model and Vuex

One of the most valuable features that Vue.js has to offer, is painless two-way data binding. By using the `v-model` directive, you can quickly set up two-way data binding on form elements...

Building a Modal Dialog with Vue.js and Vuex

Today we're building a modal dialog in Vue using Vuex. In my last article about exploratory TDD I wrote about the lack of tutorials demonstrating TDD in more complex, real world scenarios, so I decided to guide you through the whole process of building a modal dialog using the TDD methodology...

Testing Vuex Powered Vue.js Components with Jest

Thanks to the vue-test-utils, testing Vue components has become much more comfortable. But things can get a little more complicated if you add Vuex to the equation...

Speeding up Nightwatch.js Powered Acceptance Tests

Today we will examine two ways how we can speed up the testing process with Nightwatch.js – because faster is always better. The first small speed improvement can be achieved by eliminating Selenium from the setup...

Unit Testing Vue.js Single File Components with ava

Testing Vue.js components is different from testing regular JavaScript modules or classes in two ways. First of all Vue.js components depend on Vue.js, its global state and oftentimes on plugins like Vuex or the vue-router. Second, Vue.js single file components usually are compiled with webpack, the regular workflow of using Babel to compile JavaScript code before testing it, is not sufficient in this case. Let's find out how to deal with those challenges...

Acceptance Testing with Nightwatch.js and Cucumber.js Part 2: Smart Step Definitions

In an ideal world, it should be possible to write basic acceptance test specifications without having to add any new step definitions. In the real world this is not always possible, because some features, with some very specific functionality, might need special treatment and are impossible to test without writing custom step definitions...

Acceptance Testing with Nightwatch.js and Cucumber.js Part 1: Setup

Nightwatch.js is battle-tested and has proven to be a potent tool in the utility belt when it comes to conducting end-to-end tests. The combination of Nightwatch.js and Cucumber.js enables the writing of robust automated acceptance tests in plain language (Gherkin) so that every project stakeholder can read and understand the test definitions...

Setting up a PWA with Vue, Vue Router and webpack Code Splitting

Today we will create a progressive web app (PWA) based on Vue.js with Vue Router, featuring code splitting with webpack. Luckily, building progressive web apps has never been easier. Thanks to the hard work of many wonderful people in the open source community, every major JavaScript framework comes with an effortless way of kickstarting a new PWA powered project via a simple CLI command...

Payment Request API Part 3: Taxes and Discounts

Today we're going to implement taxes and discounts into our Payment Request API powered checkout process. The code is based on the code we've produced in the previous steps...

Payment Request API Part 2: Building a Shopping Cart

The first article of this three-part series was about building a very basic checkout process using the Payment Request API. In this article we're going to build a basic shopping cart implementation followed by a Payment Request API powered checkout process...

Payment Request API Part 1: Payment Process Using the Credit Card Payment Method

Thanks to the Payment Request API, accepting payments from your users now is a piece of cake. Albeit support from third party payment processors is still rather limited – Android Pay being one of the most notable – this will very likely change in the near future. Furthermore you don't necessarily need a third party payment provider to integrate directly into the Request Payment API, it is also possible to collect credit card data from the user via the Request Payment API and send them to your payment provider using it's own API...

Building a Responsive Priority+ Horizontal Scroll Navigation

One of the most difficult problems to solve when designing websites that are supposed to work well on small screens is creating user-friendly navigations. For a long time the goto solution was to hide the navigation items behind a hamburger button. Although the hamburger button is still going strong, there are some new approaches coming up and gaining traction...

The Testable Module Pattern

This is a pattern to write JavaScript modules which are fully testable by unit tests but also easy to use without the overhead of directly using a factory function. You might use this pattern when you want to use unit tests but you do not want to give up on the flexibility of a modular, dependency based approach of structuring your code...

Test Driven Development with JavaScript Using ava and Sinon.JS

For a long time testing and test-driven development (TDD) was a magical thing for me. I didn't really know what it meant and it seemed to be something only “real” developers can do correctly. Many developers suffer from imposter syndrome and so did (sometimes even today do) I and I was too scared to get into this magical thing called TDD. Two or three years ago I started to work...