Javascript 在react应用程序中使用tumblr共享链接的正确方法是什么? 从“react”导入{Component}; 从“axios”导入axios; 从“react bootstrap”导入{button}; 类仪表板扩展组件{ 建造师(道具){ 超级(道具); 此.state={ 引述:“, 作者:“, }; } componentDidMount(){ 这个.getQuote(); } getQuote(){ 让url= "https://gist.githubusercontent.com/camperbot/5a022b72e96c4c9585c32bf6a75f62d9/raw/e3c6895ce42069f0ee7e991229064f167fe8ccdc/quotes.json"; 获取(url)。然后((res)=>{ 让data=res.data.quotes; 让quoteNum=Math.floor(Math.random()*data.length); 设randomQuote=data[QuoteEnum]; 这是我的国家({ quote:randomQuote[“quote”], 作者:randomQuote[“作者”], }); }); } getNewQuote=()=>{ //将在单击“新建报价”按钮时调用 这个.getQuote(); }; render(){ const{quote,author}=this.state;//解构 返回(
{quote} {作者} 下一个报价 ); } } 导出默认仪表板; `我需要有关按钮href的帮助,因为它似乎坏了,我不明白为什么tumblr按钮不能正常工作,然后重定向到tumblr网站上的错误404页面 代码由创建一个随机报价机组成,例如每次单击后,它都会显示一个新的报价,其中包含作者的姓名,我使用axios来实现此目的'Javascript 在react应用程序中使用tumblr共享链接的正确方法是什么? 从“react”导入{Component}; 从“axios”导入axios; 从“react bootstrap”导入{button}; 类仪表板扩展组件{ 建造师(道具){ 超级(道具); 此.state={ 引述:“, 作者:“, }; } componentDidMount(){ 这个.getQuote(); } getQuote(){ 让url= "https://gist.githubusercontent.com/camperbot/5a022b72e96c4c9585c32bf6a75f62d9/raw/e3c6895ce42069f0ee7e991229064f167fe8ccdc/quotes.json"; 获取(url)。然后((res)=>{ 让data=res.data.quotes; 让quoteNum=Math.floor(Math.random()*data.length); 设randomQuote=data[QuoteEnum]; 这是我的国家({ quote:randomQuote[“quote”], 作者:randomQuote[“作者”], }); }); } getNewQuote=()=>{ //将在单击“新建报价”按钮时调用 这个.getQuote(); }; render(){ const{quote,author}=this.state;//解构 返回(,javascript,reactjs,axios,Javascript,Reactjs,Axios,{quote} {作者} 下一个报价 ); } } 导出默认仪表板; `我需要有关按钮href的帮助,因为它似乎坏了,我不明白为什么tumblr按钮不能正常工作,然后重定向到tumblr网站上的错误404页面 代码由创建一个随机报价机组成,例如每次单击后,它都会显示一个新的报价,其中包含作者的姓名,我使用axios来实现此目的' import { Component } from "react"; import axios from "axios"; i
import { Component } from "react";
import axios from "axios";
import { button } from "react-bootstrap";
class DashBoard extends Component {
constructor(props) {
super(props);
this.state = {
quote: "",
author: "",
};
}
componentDidMount() {
this.getQuote();
}
getQuote() {
let url =
"https://gist.githubusercontent.com/camperbot/5a022b72e96c4c9585c32bf6a75f62d9/raw/e3c6895ce42069f0ee7e991229064f167fe8ccdc/quotes.json";
axios.get(url).then((res) => {
let data = res.data.quotes;
let quoteNum = Math.floor(Math.random() * data.length);
let randomQuote = data[quoteNum];
this.setState({
quote: randomQuote["quote"],
author: randomQuote["author"],
});
});
}
getNewQuote = () => {
//will be called on clicking the New Quote button
this.getQuote();
};
render() {
const { quote, author } = this.state; //Destructuring
return (
<div id="wrapper">
<div id="quote-box">
<div id="text">
<p>{quote}</p>
</div>
<div id="author">
<h5>{author}</h5>
</div>
<div id="buttons">
<a
id="tweet-quote"
href={`https://twitter.com/intent/tweet?text=${quote} ${author}`}
target="_blank"
title="Post this quote on twitter!"
rel='noreferrer'
>
<span>
<i className="fab fa-twitter twitter-icon" />
</span>
</a>
<a
id="tumblr-quote"
href={`https://www.tumblr.com/widgets/share/tool?canonicalUrl=&caption=${quote} ${author}`}
target="_blank"
title="Post this quote on tumblr!"
rel='noreferrer'
>
<span>
<i className="fab fa-tumblr tumble-icon" />
</span>
</a>
<button
id="new-quote"
className="buttons"
onClick={this.getNewQuote}
>
Next Quote
</button>
</div>
</div>
</div>
);
}
}
export default DashBoard;