有没有可能在Vue.Js中更改高于body标签的任何内容?这两个元素的内容目前存储在附加到DOM树下面的元素中的JSON文件中。
我需要尝试注入可以被Google爬取的meta标题和描述(即它会在注入后呈现并被爬取),并了解访问body元素和DOM树更高层级的问题,因为当前的Vue JSON是使用位于较低位置的DIV上的App ID注入的。
在之前的一些工作中,我曾经使用过一些jQuery代码来解决这个问题,用于Square Space模板。
页面HTML
以下是翻译的结果:
我需要尝试注入可以被Google爬取的meta标题和描述(即它会在注入后呈现并被爬取),并了解访问body元素和DOM树更高层级的问题,因为当前的Vue JSON是使用位于较低位置的DIV上的App ID注入的。
在之前的一些工作中,我曾经使用过一些jQuery代码来解决这个问题,用于Square Space模板。
页面HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="{{items[0][0].meta-desc}}">
<meta name="author" content="">
<title>{{items[0][0].meta-title}}</title>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<!-- Vue.js CDN -->
<script src="https://unpkg.com/vue"></script>
</head>
<body>
<!-- Page List -->
<div class="container text-center mt-5" id="app">
<h1 class="display-4">Vue Page Output:</h1>
<h2>{{items[0][0].page1}}</h2>
</div>
<div class="container text-center mt-5">
<h3>Other Pages</h3>
<a href="products.html">Products</a>
<a href="contactus.html">Contact Us</a>
</div>
<!-- /.container -->
<script type="text/javascript">
const app = new Vue({
el: '#app',
data: {
items: []
},
created: function () {
fetch('test.json')
.then(resp => resp.json())
.then(items => {
this.items = items
})
}
});
</script>
</body>
</html>
JSON
[
[
{
"page1": "Company Name",
"meta-title": "Acme Corp"
"meta-desc": "Welcome to Acme Corp"
}
],
[
{
"products": "Product List"
}
],
[
{
"contactus": "Contact Us at Acme Corp"
}
]
以下是翻译的结果:
以下是代码演示,传入的JSON文件以固定的数组格式呈现,其中还包含元数据和正文元素。这使得处理变得有些棘手。