我们拥有并管理一些网站,我们在普通的html网站上列出了我们的网站,但我们无法将AMP发送到外部网址。
尝试使用带有amp-list参数的JSON,如下所示:
<amp-list width="auto"
height="100"
layout="fixed-height"
src="https://test.com/amp/test.json"
class="m1">
<template type="amp-mustache"
id="amp-template-id">
<div>
<a href="{{url}}">{{title}}</a>
</div>
</template>
</amp-list>
链接显示在AMP页面上,但当您点击链接时,它会转到html网站的主页。
JSON文件包含:
{
"items": [
{
"title": "Domain Name",
"url": "http://want.you"
}
]
}
答案 0 :(得分:0)
检查您的JSON ENDPOINT URL是否为CORS启用并为amp-list添加库。下面的代码在AMP操场上正常工作。
<!--
## Introduction
The [`amp-list`](https://www.ampproject.org/docs/reference/components/amp-list) component fetches dynamic content from a CORS JSON endpoint and renders it using a supplied template. This is good for embedding a dynamic list of related articles.
-->
<!-- -->
<!doctype html>
<html ⚡>
<head>
<meta charset="utf-8">
<title>amp-list</title>
<script async src="https://cdn.ampproject.org/v0.js"></script>
<!-- ## Setup -->
<!-- Import the `amp-list` component ... -->
<script async custom-element="amp-list" src="https://cdn.ampproject.org/v0/amp-list-0.1.js"></script>
<!-- ... and the `amp-mustache` component in the header -->
<script async custom-template="amp-mustache" src="https://cdn.ampproject.org/v0/amp-mustache-0.2.js"></script>
<link rel="canonical" href="https://ampbyexample.com/components/amp-list/">
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
<style amp-custom>
</style>
</head>
<body>
<amp-list width="auto"
height="100"
layout="fixed-height"
src="https://api.myjson.com/bins/pxnd8"
class="m1">
<template type="amp-mustache"
id="amp-template-id">
<div>
<a href="{{url}}">{{title}}</a>
</div>
</template>
</amp-list>
</body>
</html>