I’m trying to display data from Airtable in my Vue app and running into trouble with URL fields. I followed a basic tutorial to connect to the Airtable API but I can’t figure out how to properly convert the URL data into working links.
The problem: The URL field from Airtable isn’t displaying as a clickable link like I expected.
I encountered a similar situation with Airtable URL fields. The key detail is that the URL field returns an object that includes a url property instead of being a simple string. Your usage of record['fields']['Website']['url'] is correct for the href attribute; however, ensure you are displaying just the URL in the div. You should modify {{ record['fields']['Website'] }} to {{ record['fields']['Website']['url'] }} to show the correct link. Additionally, adding target="_blank" to your anchor tag is advisable for opening links in new tabs, which improves user experience. Lastly, always verify the existence of the URL field before accessing its properties to avoid potential errors on records lacking URLs.
Been dealing with Airtable integrations for years and this trips up a lot of people.
Your template’s got the right idea but there’s a disconnect. You’re accessing record['fields']['Website']['url'] correctly in the href, but then you’re displaying the entire object with {{ record['fields']['Website'] }} in the div below.
The main issue is that last div. You need to access the url property there too.
I wrapped that div in a v-if check because Airtable returns null or undefined for empty URL fields, which breaks your template.
One more thing - I usually add basic URL validation since users put incomplete URLs in Airtable. Check if it starts with http:// or https://. Saves you from broken links later.
airtable url fields can be a bit confusing! you gotta remember that when you call {{ record['fields']['Website'] }}, you’re getting the whole object, not just the url. try using {{ record['fields']['Website']?.url }} for your link. also, make sure to add some error checking for those empty urls – it’ll save ya from crashing the app!