Injecting into <head> in Vue.js

前端 未结 4 2080
情歌与酒
情歌与酒 2021-01-03 22:15

I have a few EXTERNAL scripts that need to be loaded on various pages, such as Google Places Autocomplete, Facebook APIs, etc.

Obviously it does not make sense to lo

4条回答
  •  情书的邮戳
    2021-01-03 22:38

    I recommend using https://www.npmjs.com/package/vue-head, it is exactly designed to inject the data you want from your component into the document's head. Perfect for SEO title and meta tags.

    To be used like so:

    export default {
      data: () => ({
        title: 'My Title'
      }),
    
      head: {
        // creates a title tag in header.
        title () {
          return {
            inner: this.title
          }
        },
        meta: [
          // creates a meta description tag in header.
          { name: 'description', content: 'My description' }
        ]
      }
    }
    

提交回复
热议问题