Values not reactive?!
See original GitHub issueI 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:
- Created 7 years ago
- Reactions:4
- Comments:13 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This week!
Production guys, follow the issue 17, to notify all of the improvements, okay. Thank you all