ktquez / vue-head

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

Read globally? #85

Closed alexcroox closed 4 years ago

alexcroox commented 4 years ago

In App.vue I have a header navigation which I would like to show the current dynamic page title that child components may have set via vue-head. Is there anyway to read the current value of vue-head globally?

I could't find anything on the Vue prototype.

For now I'm doing this but it's a bit of a hack:

App.vue

watch: {
    $route() {
      // We don't have a proper way of accessing vue-head so let's wait for a route
      // change, delay a bit for dynamic compTitles to kick in, then get the page title
      setTimeout(() => this.setPageTitle(), 100)
    }
  },
methods: {
    setPageTitle() {
      let title = document.title.split('|')
      this.pageTitle = title.length > 1 ? title.shift() : ''
    },
ktquez commented 4 years ago

Can you reproduce this in any repository or codesandbox?

alexcroox commented 4 years ago

There’s nothing to reproduce if I don’t know of the method to call (or if it even exists)

ktquez commented 4 years ago

Now I understand your question, in the current version there is no way. In version 3 of this plugin that I am developing, will have, but I have no release yet.

alexcroox commented 4 years ago

That’s exciting. Thank you for the update.