2017-12-04 13 views
1

내 웹 사이트의 소셜 공유 메타 태그를 API 호출을 통해 백엔드 데이터베이스에서 오는 데이터로 변경하려고합니다. Vue-Head => 메타 기능의 정보를 비동기식으로 변경하려면 어떻게해야합니까?

head: { 
// To use "this" in the component, it is necessary to return the object through a function 
title: function() { 
    return { 
    inner: this.title 
    } 
}, 
meta: function() { 
    return [ 
    { name: 'description', content: this.meta.description, id: 'desc' }, 
    { name: 'application-name', content: this.meta.application_name }, 
    // Twitter 
    { name: 'twitter:title', content: this.title }, 
    // with shorthand 
    { n: 'twitter:description', c: this.meta.description }, 
    // Google+/Schema.org 
    { itemprop: 'name', content: this.meta.application_name }, 
    { itemprop: 'description', content: this.meta.description }, 
    // Facebook/Open Graph 
    { property: 'fb:app_id', content: '150240095600075' }, 
    { property: 'og:title', content: this.title }, 
    // with shorthand 
    { p: 'og:image', c: 'http://jekalowa.com/static/favicon.png' } 
    ] 
} 

} 내 방법 객체

methods: { 
getAsyncData: function() { 
    var self = this 
    window.setTimeout(function() { 
    self.title = self.artist.stagename + ' | ' + self.title 
    self.meta: function() { 
     return [ 
     { name: 'description', content: this.meta.description, id: 'desc' }, 
     { name: 'application-name', content: this.meta.application_name }, 
     // Twitter 
     { name: 'twitter:title', content: this.title }, 
     // with shorthand 
     { n: 'twitter:description', c: this.meta.description }, 
     // Google+/Schema.org 
     { itemprop: 'name', content: this.meta.application_name }, 
     { itemprop: 'description', content: this.meta.description }, 
     // Facebook/Open Graph 
     { property: 'fb:app_id', content: '150240095600075' }, 
     { property: 'og:title', content: this.title }, 
     // with shorthand 
     { p: 'og:image', c: 'http://example.com/static/favicon.png' } 
     ] 
    } 
    self.$emit('updateHead') 
    }, 3000) 
} 

}

을에서 다음

페이스 북, 트위터, 링크드 인 및 Google+와 같은 사회적 공유 메타 태그와 페이지의 다른 메타 태그 정보가 모든 정보가 뒷면에서 나오기 때문에 페이지가 완전히 렌더링 (마운트 또는로드)되었을 때 변경되도록합니다. 페이지를 Facebook, Twitter, LinkedIn 및 Google+와 공유 할 때 이미지, 제목, 설명 및 정보가 데이터베이스에서 온 것입니다.

self.title = self.artist.stagename + ' | ' + self.title 
self.meta: function() { 

당신이 말할 필요가 없습니다 :

Parsing error: Unexpected token, expected ;

+0

JSON 데이터를 구문 분석하려고 시도하면 주석 기호 // – samayo

+0

@ samayo를 제거하려는 경우 주석을 제거 할 수 있으므로 문제가되지 않습니다. 이 줄에서 정확하게 오류가 발생합니다. self.meta : function() { – ERSS

+0

@ERSS 이것을 알아 냈습니까? –

답변

0

것은 내가 생각 여기에 문제가 될 것 같다 않습니다 웹팩 코드를 컴파일 할 때 나는 이러한 오류를 얻을 수

self.meta = function() ... OR { ... } ? 

분명히 여기에 구문 오류가 있다고 생각합니다.