👉🏻 Fotis demonstrates that using Vue with TypeScript brings many benefits.
👉🏻 With features like typed props, emits, slots, state management, and generics, it noticeably improves the readability of a codebase and ensures everything works as expected.
👉🏻 "In short words, we will be sending a request under the hood for the next resources so that when user clicks the load more button, they will instantly see the result."
Eager delay spinners are not a good user experience as they can make a snappy user interface feel slower. We can provide a better user experience (UX) by delaying spinners to appear only after a perceivable delay.
To achieve this improved UX, you can use AsyncComponent. Vue provides the defineAsyncComponentdefineAsyncComponent function to lazy load components:
1<template>2 <AsyncComp />3</template>45<script setup>6import { defineAsyncComponent } from 'vue'78const AsyncComp = defineAsyncComponent(() => {9 return new Promise((resolve, reject) => {10 // ...load component from server11 resolve(/* loaded component */)12 })13})14</script>
defineAsyncComponentdefineAsyncComponent accepts a loader function that returns a Promise. The resolveresolve callback should be called if the component has been loaded, and the rejectreject callback to indicate that loading the component has failed.
Now let's implement the delayed loading spinner by using the advanced options of the defineAsyncComponentdefineAsyncComponent function:
1<template>2 <AsyncComp />3</template>45<script>6import { defineAsyncComponent } from 'vue'7import Loading from './components/Loading'89export default {10 components: {11 AsyncComp: defineAsyncComponent({12 // the loader function13 loader: () =>14 new Promise((resolve) => {15 setTimeout(() => {16 resolve(import('./components/HelloWorld.vue'))17 }, 2000)18 }),1920 // A component to use while the async component is loading21 loadingComponent: Loading,22 // Delay before showing the loading component. Default: 200ms.23 delay: 500,24 }),25 },26 data() {},27}28</script>
This demo simulates a network request to fetch HelloWorld.vueHelloWorld.vue from a server which takes 2 seconds:
👉🏻 Ever wondered why cookies are not passed correctly to subrequests - e.g. during SSR or when using Nitro/H3?
👉🏻 Alexander takes a look at how to pass all the important information, including event context and headers to further calls, eliminating different behavior on server and client.
Weekly Vue News #141 Share Styling Using Wrapper Components View online Hi 👋 I got the opportunity to raffle 3 in-person tickets for the first edition of the C3 Dev Festival in Amsterdam. You can participate here. Have a nice week ☀️ Vue 📕 Effortless Forms w/ FormKit 👉🏻 This article on FormKit teaches you how to build forms effortlessly, with a focus on great UX. 📕 Vue Tip: Best Practices for Working with Slots 👉🏻 When developing with slots in Vue.js, it's important to follow some best practices to ensure clean and maintainable code. 📹 This is the Future of Vue 👉🏻 Matt took a look at what exactly makes Vue Vapor so exciting. 📹 Should You Use Vue Slots Over Props? 👉🏻 John talks about the pros & cons of using Vue slots instead of props. 🛠️ Pinia Colada 👉🏻 An opinionated yet flexible data fetching layer on top of Pinia. 👉🏻 It's still experimental and not ready for production. 🛠️ vue-tel-input 👉🏻 International Telephone Input with Vue. 🔥 Vue Tip: Share S...
Tuesday, October 8, 2024 Podcast : I was able to write a post that appeared on Mastodon using ActivityPub. Via the WordPress API. Congrats to the ActivtyPub community, Automattic and Mastodon. "It just worked." # Okay this is blowing my mind. My friends at Automattic showed me how to turn on ActivityPub on a WordPress site. I wrote a test post in my simple WordPress editor, forgetting that it would be cross-posted to Mastodon. When I just checked in on Masto, there was the freaking post . After I recovered from passing out, I wondered what happens if I update the post in my editor, and save it to the WordPress site that's hooked up to Masto via ActivityPub. So I made a change and saved it. I waited and waited, nothing happened. I got ready to add a comment saying ahh I guess it doesn't update, when -- it updated. Oh geez look at that. Folks, I did nothing here but write an app that can be used to edit WordPress posts. And I got in return an app that...
Weekly Vue News #194 Reactive Time Ago View online Hi 👋 I'm on vacation this week, so no special news from my side — just some fresh Vue & Nuxt content for you! Enjoy this issue and have a lovely week ☀️ Vue 📕 Optimizing heavy operations in Vue with Web Worke...
评论
发表评论