I am using wordpress rest api and am getting encoded title strings from the server. I want to decode the string before I use it to replace the document.title.
Wordpress api
{
"id": 698,
"title": {
"rendered": "Ludovico Einaudi – “Divenire”"
},
}
actions.js
export default {
updateDocTitle ({ state, commit }, { parts = [], sep = ' – ' }) {
commit('SET_DOC_TITLE', parts.join(sep))
document.title = state.site.docTitle
},
}
Tried document.title = decodeURI(state.site.docTitle)
- doesn't work
mutations.js
export default {
SET_DOC_TITLE(state, title) {
state.site.docTitle = title
}
}
Tried state.site.docTitle = decodeURI(title)
- doesn't work
Component
computed: {
post() {
return this.$store.getters.singleBySlug(this.request)
}
},
methods: {
getPost() {
this.$store.dispatch('getSingleBySlug', this.request).then(() => {
this.$store.dispatch('updateDocTitle', { parts: [ this.post.title.rendered, this.$store.state.site.name ] })
})
}
},
created() {
this.getPost()
}
Tried this.$store.dispatch('updateDocTitle', { parts: [ decodeURI(this.post.title.rendered), this.$store.state.site.name ] })
- doesn't work