In this episode, we're diving into the basics of handling profile photos for users. We start by making sure that each user gets a proper default profile photo rather than a static placeholder. To achieve this, we modify our user model and resource to dynamically generate an avatar URL—using an API like UI Avatars that pulls from the user's name.
After that's in place, we head over to the UI and set up the profile photo area. We walk through creating a layout where the avatar sits on one side and a button to upload or change the photo is on the other. By connecting a file input to our Vue state, we let users select a new photo, and we instantly show a preview using a computed property to generate an image from the selected file.
We also set up the user experience so that if someone changes their mind, they can click a button to clear their chosen photo and reset everything back to the default. All the while, we tweak styling and add conditional rendering so that everything looks and functions smoothly.
By the end, we've built a flexible avatar upload and preview component. Next up: wiring this to actually upload and save the photo to the backend!