In this episode, we focus on setting up a simple modal to display the response body when you click on a certain button (like 'Add Site') in our app. We've already integrated the view-final-modal
package earlier for the site selector, so we're building off that foundation for a quick solution.
We start by reusing some modal code we had before, trimming out the unnecessary form fields since all we need now is a way to show the response body. To control when the modal appears, we introduce a new reactive ref
in Vue called showResponseBodyModal
, and tie this to the open/close state of our modal.
Clicking the button sets this to true, and boom – the modal pops up with our response body. We do note that this current approach means a modal component gets rendered for each response (not super optimal if you have a ton, but it's fine for now).
For displaying the response body itself, we use a textarea
. We bind the value from the response, make it readonly (so users can't edit), add some simple Tailwind CSS like borders and rounded corners, set the width to full, and specify the number of rows for a clean look. Now when the modal opens, you see your response in a nice, scrollable, uneditable text area—easy to select and copy from if you need. That's all for viewing the response body in a modal!