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.
Vue-Tipps · 132 Tipps
In den letzten Jahren habe ich beim Entwickeln und Schreiben über Vue & Nuxt eine Liste wertvoller Tipps gesammelt. Einige sind clever, einige benutze ich fast jeden Tag, und einige sind fortgeschrittener - aber sie sind alle nützlich.
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.
To declare emits with full type inference support, we can use the defineEmits API, which is automatically available inside <script setup>.
I will show you a few ways how you can easily change the page title when navigating your application
To access the DOM after Vue has updated it in a watcher callback, you can use the flush post option.'
Sometimes we need to pass custom arguments to the event handler method and access the original DOM event.
Mutating props is an anti-pattern. You should use computed properties instead.
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.
Adding routes to your router is usually done via the `routes` option, but in some situations, you might want to add or remove routes while the application is already running.
Usually, the Vue Devtool extension is disabled in production builds, but there is a way to force-enable it.
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.
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.
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.
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.
It is possible to sync composable state across components by lifting its definition outside the exported function.
Components using script setup are closed by default and will not expose any of the bindings declared inside script setup.
Third-party components are often wrapped in a custom component. But in that way, the slots of the third-party component get lost.
Vue provides two lifecycle hooks that we can use for debugging purposes.
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.
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 Testing Library is my preferred Vue.js testing library that encourages good testing practices.
In addition to the default set of directives like v-model or v-show, you can also register your own custom directives.
It is a no-go to manipulate the DOM in Vue.js directly. Instead, you should use the "ref" attribute.
Vue provides an object that can be used to register global properties that can be accessed on any component instance inside the application.
v-if has higher toggle costs while v-show has higher initial render costs.