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: Use v-bind to Pass Multiple Props to Components Image

Vue Tip: Use v-bind to Pass Multiple Props to Components

Instead of passing each property individually to a component, you can bind an object to it.
Vue Tip: Watch Nested Values Image

Vue Tip: Watch Nested Values

The watch options support a dot-delimited path as key to watch nested values.
Vue Tip: Use Vuex in Vue Router Navigation Guards Image

Vue Tip: Use Vuex in Vue Router Navigation Guards

It's possible to use Vuex state to determine if a user is allowed to visit certain Vue Router routes.
Vue Tip: Special CSS Selectors Image

Vue Tip: Special CSS Selectors

Vue provides some special CSS pseudo-selectors you can use in your Vue SFC.
Vue Tip: Use Optional Chaining in Templates Image

Vue Tip: Use Optional Chaining in Templates

It's possible to use optional chaining in Vue templates.
Vue Tip: Use Two Script Blocks  Image

Vue Tip: Use Two Script Blocks

<script setup> can be used alongside normal <script>. A normal <script> may be needed in special cases.
Vue Tip: Speed Up Initial Load Using Async Components Image

Vue Tip: Speed Up Initial Load Using Async Components

Using async components is a great way to speed up the initial load time of your app.
Vue Tip: Scroll to Top When Navigating to a New Route Image

Vue Tip: Scroll to Top When Navigating to a New Route

When using client-side routing, we may want to scroll to top when navigating to a new route, or preserve the scrolling position of history entries just like real page reload does.
Vue Tip: Display Raw HTML Image

Vue Tip: Display Raw HTML

The double mustaches interpret the data as plain text, not HTML. To output real HTML, you will need to use the v-html directive.
Vue Tip: Automatic Global Registration of Base Components Image

Vue Tip: Automatic Global Registration of Base Components

We can use webpack to register our Vue.js base components globally.