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.

#60

Nuxt Tip: Adding a Latest Route

Utilizing Nuxt Middleware, you can implement an easy way for visitors to always read the latest blog posts (or any other content) without needing to know its name or specific URL.

1 minNuxt
#59

Vue Tip: Typing Component Events

To declare emits with full type inference support, we can use the defineEmits API, which is automatically available inside <script setup>.

1 minScript
#54

Vue Tip: Disable Attribute Inheritance

By default, parent scope attribute bindings that are not recognized as props will "fallthrough". This may not always be the desired behavior and, therefore, can be disabled. A typical use case is a component with multiple root nodes.

1 minTemplate
#51

Vue Tip: Use Provide & Inject to Avoid Prop Drilling

Props are the standard way to pass data from the parent to a child component. Sometimes, we want to share data from a parent component to all its children components without using a store. Provide / Inject solves this problem and avoids prop drilling.

2 minScript
#50

Vue Tip: Change the Interpolation Delimiter

It is possible to adjust the delimiters used for text interpolation within the template to avoid conflicting with server-side frameworks that also use mustache syntax.

1 minTemplate
#49

Vue Tip: Use Vue Without Build Step

When using Vue from a CDN, no "build step" is involved. This makes the setup much more straightforward and is suitable for enhancing static HTML or integrating with a backend framework.

1 minTemplate
#48

Vue Tip: Defining and Registering Vue Web Components

Web Components is an umbrella term for a set of web native APIs that allows developers to create reusable custom elements. Vue has excellent support for both consuming and creating custom elements.

1 minTemplate
#43

Vue Tip: Typing Template Refs With TypeScript

Template refs only exist after the component is mounted. Thus, it’s necessary to type template refs with a union type that includes the DOM element type as well as null.

1 minTemplate
#40

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.

2 minTemplate
#37

Vue Tip: When to Use v-if

v-if has higher toggle costs while v-show has higher initial render costs.

1 minTemplate
Page 4 of 6