Created
October 21, 2021 11:21
-
-
Save clampr/997e74b92cbc63069cf6ff9af0cc4f09 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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