Answers for "Npx async fetch() {"

0

Npx async fetch() {

async fetch() {
  const article = await fetch(
    `https://dev.to/api/articles/${this.$route.params.article}`
  ).then((res) => res.json())

  if (article.id && article.user.username === this.$route.params.username) {
    this.article = article
    this.$store.commit('SET_CURRENT_ARTICLE', this.article)
  } else {
    // set status code on server
    if (process.server) {
      this.$nuxt.context.res.statusCode = 404
    }
    // throwing an error will set $fetchState.error
    throw new Error('Article not found')
  }
}
Posted by: Guest on June-04-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language