While there's not much excitement to report from my end this time around, I do have something special for you! I've snagged a ticket to the Vue.js Live 2024 Online conference, and I'm thrilled to raffle it off to one lucky subscriber. Check out the link below for your chance to join in on the action!
👉🏻 In this crash course David East will take you through all of the basics and build an Vue app using Authentication, Firestore, and Vue Router with VueFire.
👉🏻 In this article, we will learn how to build an static web app using Nuxt, with serverless APIs using Azure Functions CLI and Static Web Apps Emulator.
🔥 Vue Tip: Validate Props in Script Setup With TypeScript
You can define prop validations for your component in the script setupscript setup using the defineProps()defineProps() compiler macro. This is a great way to ensure that the props you receive are of the correct type and shape.
Let's first take a look at the official example from the Vue docs without using TypeScript:
1<script setup>2defineProps({3 // Basic type check4 // (null and undefined values will allow any type)5 a: Number,6 // Multiple possible types7 b: [String, Number],8 // Required string9 v: {10 type: String,11 required: true,12 },13 // Number with a default value14 d: {15 type: Number,16 default: 100,17 },18 // Object with a default value19 e: {20 type: Object,21 // Object or array defaults must be returned from22 // a factory function. The function receives the raw23 // props received by the component as the argument.24 default(rawProps) {25 return { message: 'hello' };26 },27 },28 // Custom validator function29 // full props passed as 2nd argument in 3.4+30 f: {31 validator(value, props) {32 // The value must match one of these strings33 return ['success', 'warning', 'danger'].includes(value);34 },35 },36 // Function with a default value37 g: {38 type: Function,39 // Unlike object or array default, this is not a factory40 // function - this is a function to serve as a default value41 default() {42 return ['one, two'];43 },44 },45});46</script>
Now let's rewrite the same example using TypeScript inside script setupscript setup:
All we need to do is define an interface for the props and use the withDefaultswithDefaults helper to set default values. TypeScript will take care of the rest.
👉🏻 Google introduced Interaction to Next Paint (INP) as a new Core Web Vital on March 12 to emphasize the importance of a website's overall responsiveness throughout a user's entire visit.
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...
Hey! In yesterday's email I shared what I think is the key feature to making Vue components highly reusable: Scoped slots. But scoped slots are hard to grasp, and even more difficult to master. So today, we're going to make sure we understand them on a deep, intuitive level. Then, I'm going to introduce you to the magic ✨ of scoped slots. The trick is to think of them as functions. Slots are just functions We're going to recreate the functionality of slots, but we'll use a regular Javascript function that only returns HTML. This is the code we'll replicate: <!-- Parent --> < template > < div class = "modal-container" > < div class = "modal" > Content in the Parent < Child class = "mb-4" v-slot = "{ text }" > ...
评论
发表评论