使用案例
1. 安装
npm install vue-meta --save
2. main.js 中
import Meta from 'vue-meta'
Vue.use(Meta)
- app.vue页面中
<template>
<div id="app">
<!-- <div id="nav">
<router-link to="/">Home</router-link> |
</div> -->
<router-view />
</div>
</template>
<script>
import { keyWord } from "./assets/js/index.js";
export default {
data() {
return {
title: "",
description: "",
description2: "",
};
},
metaInfo() {
return {
title: this.title,
meta: [
{ vmid: "description", name: "description", content: this.description },
{
vmid: "keywords",
name: "keywords",
content: this.description2,
},
],
};
},
created() {
this.initData();
},
methods: {
initData() {
keyWord({
siteId: window.localStorage.getItem("siteId"),
}).then((res) => {
if ((res.code = 200)) {
this.title = res.data.index_title;
this.description = res.data.desc;
this.description2 = res.data.keys;
}
});
},
},
};
</script>
<style>
</style>