yarn add vue-meta-info
npm install vue-meta-info --save
import MetaInfo from 'vue-meta-info'
Vue.use(MetaInfo)
<script>
export default {
metaInfo: {
title: '页面title', //设置页面title
meta: [{ //设置页面meta
name: 'keyWords',
content: '关键词'
},
{
name: "description",
content: "描述",
},]
}
}
</script>
<script>
export default {
metaInfo() {
return {
title: this.PageTitle,
meta: [
{
name: "keyWords",
content: this.PagekeyWords,
},
{
name: "description",
content: this.PageDescription,
},
],
};
},
data () {
return {
PageTitle: "",
PagekeyWords: "",
PageDescription: "",
}
},
mounted (){
setTimeout(() => {
this.PageTitle = '页面title'
this.PagekeyWords = '页面关键词'
this.PageDescription = '页面描述'
},2000)
}
}
</script>
如果需要更好的处理 Vue 单页面SEO,可以和 prerender-spa-plugin形成更优的配合,请看我另一篇文章哦