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.

Nuxt Tip: Change Status Code of the Response Image

Nuxt Tip: Change Status Code of the Response

`setResponseStatus` is a Nuxt composable to set the status code and (and optionally the status message) of the response.
Nuxt Tip: Run Code Once During SSR or CSR Image

Nuxt Tip: Run Code Once During SSR or CSR

Since Nuxt 3.9 you can use the useOnce composable to run a given function or block of code once during server-side rendering or client-side navigation.
Vue Tip: How I Write Class & Style Bindings Image

Vue Tip: How I Write Class & Style Bindings

Styling your components in Vue.js can be done in multiple ways. One of the most common ways is to use the class attribute, especially if you are using a CSS framework like Tailwind. In combination with v-bind you can dynamically assign classes to your components.
Vue Tip: When You Should Use a Composable Image

Vue Tip: When You Should Use a Composable

Vue composables are a way to encapsulate logic in a reusable way in Vue 3. They are a great way to share logic between components, but I often see them used in places where they are not needed.
Vue Tip: Mutate Your State Inside of the Provider Using Provide and Inject Image

Vue Tip: Mutate Your State Inside of the Provider Using Provide and Inject

When using reactive provide/inject values, it is recommended to keep any mutations to reactive state inside of the provider whenever possible.
Vue Tip: Share Styling Using Wrapper Components Image

Vue Tip: Share Styling Using Wrapper Components

Wrapper components can help you share styling across multiple Vue components. This can make your code cleaner and more maintainable.
Nuxt Tip: Use Environment-Specific Configurations Image

Nuxt Tip: Use Environment-Specific Configurations

It sometimes happens that you need to have different configurations for different environments in your Nuxt.js application. Therefore, Nuxt provides fully typed, per-environment overrides for your Nuxt configuration.
Vue Tip: Validate Props in Script Setup With TypeScript Image

Vue Tip: Validate Props in Script Setup With TypeScript

For prop validations inside `<script setup>` with TypeScript you need to define an interface for the props and use the `withDefaults` helper to set default values.
Nuxt Tip: How Nuxt Uses Nitro, h3 and ofetch Internally Image

Nuxt Tip: How Nuxt Uses Nitro, h3 and ofetch Internally

Nitro, h3 and ofetch are UnJS packages that are used to power the Nuxt 3 server engine.
Vue Tip: Don't Use Reactive Object for Template Refs Image

Vue Tip: Don't Use Reactive Object for Template Refs

Template Refs are a way to access elements in the DOM from within a Vue component. As the name suggests, you should use a ref to access the element in the template.