ktquez / vue-head

Manager the meta information of the head tag, a simple and easy way
MIT License
984 stars 73 forks source link

updateHead add's the changed meta instead of updating #84

Closed sstenn closed 4 years ago

sstenn commented 4 years ago

I use the updateHead function to change the meta data when the language is changed. But instead of updating the current meta, the tags get added.

I use a mixin to set the meta and watch the language state:

export const meta = {
  head: {
    title: function () {
      var title = this.$store.state.activePage.Main.Meta[this.$store.state.language].Title
      if (title && title !== '') {
        return {
          inner: title
        }
      }
    },
    meta: function () {
      var meta = []
      var page = this.$store.state.activePage.Main
      var items = ['Title', 'Description', 'Image']
      for (var i = 0; i < items.length; i++) {
        var content = page.Meta[this.$store.state.language][items[i]]
        var name = items[i].toLowerCase()
        if (content && content !== '') {
          meta.push({ name: name, content: content })
          meta.push({ name: 'twitter:' + name, content: content })
          meta.push({ property: 'og:' + name, content: content })
        }
      }
      return meta
    }
  },
  watch: {
    '$store.state.language' (val) {
      this.$emit('updateHead')
    }
  }
}

The watch function is triggered when the language is changed. And as I said, the meta is added instead of updated.

Schermafbeelding 2019-10-25 om 11 25 31
ktquez commented 4 years ago

@sstenn You can add an id attribute https://github.com/ktquez/vue-head#replace-content-the-elements

ktquez commented 4 years ago

I closed the issue, but if you still have questions, just open again, ok?

sstenn commented 4 years ago

Issue is solved. Thanks for your response

MarcelloTheArcane commented 3 years ago

~@ktquez I'm getting this on an added style tag - I have an ID set but it's not removing the old tag. Does this replace only work for some elements?~

Sorry, false alarm. It's Webpack messing around!