我正在使用 Star Wars API 构建一个 React JS 项目。我的应用程序的目标是能够搜索字符。
这是我的应用程序中搜索组件的代码。
目前,我可以通过 API 检索数据并在页面上显示信息,但我无法弄清楚在搜索时如何显示这些信息。
有任何想法吗?
import React, { Component } from 'react';
class Search extends Component {
constructor(props){
super(props)
this.state = {
query:'',
peoples: [],
}
}
onChange (e){
this.setState({
query: e.target.value
})
if(this.state.query && this.state.query.length > 1) {
if(this.state.query.length % 2 === 0){
this.componentDidMount()
}
}
}
componentDidMount(){
const url = "https://swapi.co/api/people/";
fetch (url,{
method:'GET'
}).then(results => {
return results.json();
}).then(data => {
let peoples = data.results.map((people) => {
return(
<ul …Run Code Online (Sandbox Code Playgroud) 我正在使用 ReactJS,我想要一个字符串,然后是一个链接,如下所示
const example = "Hello I'm a string" + <a href="/link">And this is a link</a>
Run Code Online (Sandbox Code Playgroud)
目前我不断得到 Hello I'm a string [object Object]
如何让文本和链接正确连接?