skip to Main Content

how can i pass my api Value to Header title on vue? im using nuxt.

I try using this but i got error ‘blog is not defined’

async asyncData({params, error}) {
        try {
            let topBlogger = await axios.get('http://api.bla.bla/API/topblogger.php')
            let isi = await axios.get(`http://api.bla.bla/API/news.php?id_artikel=${+params.id}`)
            let tagList = await axios.get('https://api.bla.bla/users')
            return {
                bloggers: topBlogger.data,
                blog: isi.data,
                tags: tagList.data,

            }
        } catch (e) {
            error({message: 'User not found', statusCode: 404})
        }
    },
head () {

        return {
            title: blog.id_artikel+' | title bla bla',
            meta: [
                { hid: 'description', name: 'description', content: 'content dll' }
            ]
        }
    },

but when i use blog on <template></template> it work
i’m new on vueJS so still can’t seem understand well how it work

2

Answers


  1. You need to access data using this

    return {
                title: this.blog.id_artikel+' | title bla bla',
                meta: [
                    { hid: 'description', name: 'description', content: 'content dll' }
                ]
            }
    
    Login or Signup to reply.
  2. This may be helpful for you.

    <script>
    export default {
     head: {
     title: this.blog.id_artikel+' | title bla bla',
     meta: [
     {
            hid: 'description',
            name: 'description',
            content: 'Home page description'
          }
        ],
      }
    }
    </script>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search