Skip to content

Instantly share code, notes, and snippets.

@clampr
Created October 21, 2021 11:21
Show Gist options
  • Save clampr/997e74b92cbc63069cf6ff9af0cc4f09 to your computer and use it in GitHub Desktop.
Save clampr/997e74b92cbc63069cf6ff9af0cc4f09 to your computer and use it in GitHub Desktop.
import { defineComponent } from 'vue'
export default defineComponent({
name: 'Station',
props: {
station: {
type: Object,
default: null
}
},
data(): Record<string, any> {
return {
meta: this.station || null
}
},
async mounted(): Promise<void> {
if (!this.station) {
// Get meta data
await this.fetchMetaData()
}
},
methods: {
/**
* Fetch station meta data
*/
async fetchMetaData(): Promise<void> {
await fetch(`/stations/meta?id=${this.$route.params.id}`)
.then(response => response.json())
.then(data => this.meta = data.data)
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment