【发布时间】:2020-03-24 18:40:46
【问题描述】:
我正在使用 Gatsby 中的 gatsby-source-google-spreadsheet 插件来创建页面上的元素列表。该插件是使用我的表格设置的,并且运行良好。当我从工作表中拉入链接时,我正在努力解决如何将链接作为<a href> 插入。
src/pages/index.js:
import React from "react"
import { graphql } from "gatsby"
export default ({ data }) => {
const sheetData = data.allGoogleSpreadsheetSheetSheet.nodes;
const rendered = sheetData.map(item =>
<div className="section">
<div className="section__when"> {item.day}, {item.date} at {item.time} </div>
<div className="section__host"> {item.event}, {item.host} </div>
<div className="section__link"> <a href="{item.link}" target="_blank">Access here. </a></div>
<div className="section__description"> {item.description} </div>
</div>);
return rendered;
};
export const query = graphql`
query {
allGoogleSpreadsheetSheetSheet {
nodes {
event
host
link
day
time
date
description
}
}
}
`;
这给了我一个合适的列表,但是当我点击链接时,它试图带我去:http://localhost:8000/%7Bitem.link%7D,这显然是错误的。现在,我的表格只有每个条目的链接https://www.google.com。如何更改链接 div 的结构方式以将我带到外部链接?
【问题讨论】:
标签: javascript reactjs graphql gatsby