Vue tips · 132 tips

Vue & Nuxt tips

Over the last few years, I've collected a list of valuable tips while developing and writing about Vue & Nuxt. Some are clever, some I use almost every day, and some are more advanced — but they're all useful.

Vue Tip: Avoid Side Effects in Computed Properties Image

Vue Tip: Avoid Side Effects in Computed Properties

It is considered bad practice to introduce side effects inside computed properties and functions because it makes the code unpredictable and hard to understand.
Vue Tip: Test Vue Components Using Vue Testing Library Image

Vue Tip: Test Vue Components Using Vue Testing Library

Vue Testing Library is my preferred Vue.js testing library that encourages good testing practices.
Vue Tip: Creating a Custom Directive Image

Vue Tip: Creating a Custom Directive

In addition to the default set of directives like v-model or v-show, you can also register your own custom directives.
Vue Tip: Avoid Directly DOM Manipulation Image

Vue Tip: Avoid Directly DOM Manipulation

It is a no-go to manipulate the DOM in Vue.js directly. Instead, you should use the "ref" attribute.
Vue Tip: Use Vue App Instance as Global Store Image

Vue Tip: Use Vue App Instance as Global Store

Vue provides an object that can be used to register global properties that can be accessed on any component instance inside the application.
Vue Tip: When to Use v-if Image

Vue Tip: When to Use v-if

v-if has higher toggle costs while v-show has higher initial render costs.
Vue Tip: Avoid Empty Wrapper for Conditions Image

Vue Tip: Avoid Empty Wrapper for Conditions

There are many situations when you need to conditionally display multiple Vue components. To avoid "empty" wrappers you should use not use HTML tags.
Vue Tip: Delay Loading Appearance of Spinner Image

Vue Tip: Delay Loading Appearance of Spinner

Eager delay spinners are not a good user experience. They can make a snappy user interface feel slower. We want delay spinners to appear only after a perceivable delay.
Vue Tip: Check if Slot Is Empty Image

Vue Tip: Check if Slot Is Empty

You can check if a slot is empty, for example, only to render it if it has content.
Vue Tip: Memoize a Sub-Tree of the Template Using v-memo Image

Vue Tip: Memoize a Sub-Tree of the Template Using v-memo

The v-memo directive is like a computed prop for the template.