I’m working on a Vue.js project where I need to display data from Airtable and convert URL fields into proper clickable links.
I’ve successfully connected to the Airtable API and can display basic field data, but I’m struggling with formatting URL fields properly. The URLs are coming through as objects rather than simple strings, and I need to extract the actual URL value to create working href attributes.
Here’s my current template setup:
<div id="main-app">
<div class="content-grid">
<div v-for="record in records" class="item-card">
<h2>{{ record['fields']['CompanyName'] }}</h2>
<a :href="record['fields']['Website']['url']" v-if="record['fields']['Website']">
<span>Visit: {{ record['fields']['Description'] }}</span>
</a>
<div>
<em>URL Data: </em>
{{ record['fields']['Website'] }}
</div>
</div>
</div>
</div>
And here’s my Vue component logic:
var mainApp = new Vue({
el: "#main-app",
data: {
records: []
},
mounted: function() {
this.fetchRecords();
},
methods: {
fetchRecords: function() {
var component = this;
var base_id = "your-base-id";
var api_token = "your-api-token";
this.records = [];
axios
.get(
"https://api.airtable.com/v0/" +
base_id +
"/Companies?view=Main%20View",
{
headers: { Authorization: "Bearer " + api_token }
}
)
.then(function(result) {
component.records = result.data.records;
})
.catch(function(err) {
console.log(err);
});
}
}
});
The problem is that the URL field returns an object with nested properties instead of just the URL string. How do I properly access and format these URL fields to create working links in my Vue template?