question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Values not reactive?!

See original GitHub issue

I want to update the title and meta-tags after the page-content is loaded via REST-API, so the final values don’t exist when the component is created.

Unfortunately, the meta-tags and title won’t react to changes in the data-variables:

<template lang="pug">
  .sections
</template>

<script>
import { fetchData }                  from '../../../js/mixins'

export default {
  name: 'HomeTemplate',
  data () {
    return {
      [...],
      getcontent: {
        contents: {
          myTitle: ''
        }
      }
      meta: {
        myTitle: ''
      }
    }
  },
  [...],
  head: {
    title: function () {
      return {
        inner: this.meta.myTitle
      }
    },
    meta: function () {
      return [
        { name: 'description', content: this.meta.myTitle, id: 'desc' }
      ]
    }
  },
  methods: {
    [...],
    setMetaData () {
      if (typeof this.getcontent !== 'undefined') {
        if (this.getcontent.contents.headline !== '') {
          this.meta.myTitle = this.getcontent.contents.headline
        }
      }
    },
    fetchMyData () {
      const _this = this
      let contentPath = ''
      let teaserPath  = ''

      // Set API-Paths
      if (process.env.NODE_ENV === 'development') {
        contentPath   = '../../static/testData/contents/home.json'
        teaserPath    = '../../static/testData/contents/home_teaser.json'
      } else {
        contentPath   = '/?_format=json'
        teaserPath    = '/rest_extended/front_content?_format=json'
      }

      // Fetch Data
      fetchData(_this, contentPath, 'getcontent', function () {
        fetchData(_this, teaserPath, 'teasers', function () {
          _this.setMetaData()
        })
      })
    }
  }
}
</script>

this.meta.myTitle changes correctly in the vue-console, but nothing happens in the <title> or <meta name="description">

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:4
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
ktquezcommented, Sep 4, 2016

This week!

1reaction
ktquezcommented, Sep 8, 2016

Production guys, follow the issue 17, to notify all of the improvements, okay. Thank you all

Read more comments on GitHub >

github_iconTop Results From Across the Web

vue.js - Why not reactive property are reactive in my template?
A ref s value is saved in its value property, whereas a normal not reactive variable can be directly accessed.
Read more >
Reactivity Fundamentals - Vue.js
When you access this.someObject after assigning it, the value is a reactive proxy of the original newObject . Unlike in Vue 2, the...
Read more >
Ref vs Reactive - Vue.js Developers
One advantage of reactive is that it doesn't use a value property so it may be a little easier to read. data.name ===...
Read more >
shallowReactive inside a reactive object is not respected ...
Values inside the array are not reactive only the first time. When a new shallow reactive array is assigned, then its values become...
Read more >
Non-reactive Objects in Vue Composition API
value = await fetchUsers();. shallowReactive on the other hand only makes the defined properties reactive, but not their contents if they are ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found