vue-meta-info:
安装:
npm install vue-meta-info --save
全局引入vue-meta-info,在main.js
import Vue from ‘vue‘
import MetaInfo from ‘vue-meta-info‘
Vue.use(metaInfo)
组件内静态使用metaInfo
<script>
export default {
metaInfo: {
title: ‘新闻页面‘,
meta: [{
name: ‘keyWords‘,
content: ‘新闻‘
}]
}
}
</script>
如果你的title或者meta不是静态的,是需要异步加载的::用metaInfo() 方法
<script>
export default {
name: ‘async‘,
metaInfo() {
return {
title: this.pageName
}
},
data() {
return {
pageName: ‘loading‘
}
},
mounted (){
setTimeout(() => {
this.pageName = ‘async‘
},2000)
}
}
</script>