我昨天做了以下文件。
# import flask
from flask import Flask
from flask import render_template
from flask import request
app = Flask(__name__)
# create url & function mapping for root or /
@app.route('/')
def index():
return "Hello from Flask"
# create another mapping name /hello
@app.route('/hello')
def hello():
myName = "kayak"
return "Hello again !!" + myName
# create mapping for /myprofile
@app.route('/myprofile')
def showmyprofile():
return render_template('myprofile.html')
# create mapping for /myprofile
@app.route('/addprofileform')
def addprofileform():
return render_template('myprofileform.html')
# create a mapping for /addprofile …
Run Code Online (Sandbox Code Playgroud) 我正在 React 中制作添加到收藏夹功能。感谢大家的帮助,除了切换喜欢和不喜欢之外,我可以以某种方式完成这项工作。我编码为“likes: this.state.likes.filter(e => e.name !== person.name)”只是因为有人建议我这样编码。说实话,我不明白上面的代码,可能是因为它是 ES6 语法。在 ES5 中是什么样子的?现在代码不起作用,元素没有正确添加到数组中。我该如何修复此代码?
import React from 'react';
import axios from 'axios';
import IcoMoon from 'react-icomoon';
export default class PersonList extends React.Component {
state = {
persons: [],
likes: []
}
componentDidMount() {
axios.get(`https://jsonplaceholder.typicode.com/users`)
.then(res => {
const persons = res.data;
this.setState({ persons });
})
}
handleClick = person => {
if (this.state.likes.filter(e => e.name === person.name).length > 0) {
this.setState({
likes: this.state.likes.filter(e => e.name !== person.name)
});
console.log(this.state.likes);
return;
}
this.setState({ …
Run Code Online (Sandbox Code Playgroud) 我试图改变颜色只有第三个但由于某种原因css nth-of-type不起作用......
ul li a:nth-of-type(3){
color: #111111;
}
Run Code Online (Sandbox Code Playgroud)
<ul>
<li class="nav_menu"><a id="currentlink" href="#">HOME PAGE</a></li>
<li class="nav_menu"><a href="homework/homework2/index.html">II</a></li>
<li class="nav_menu"><a href="#">III</a></li>
<li class="nav_menu"><a href="#">IV</a></li>
<li class="nav_menu"><a href="#">V</a></li>
<li class="nav_menu"><a href="#">VI</a></li>
<li class="nav_menu"><a href="#">VII</a></li>
<li class="nav_menu"><a href="#">VIII</a></li>
<li class="nav_menu"><a href="#">IX</a></li>
<li class="nav_menu"><a href="#">X</a></li>
</ul>
Run Code Online (Sandbox Code Playgroud)
我该如何解决?谢谢您的帮助.
我正在使用OpenWeatherMap API在React中创建一个天气应用程序。有输入表单和一个按钮,当我单击该按钮时,我希望看到城市名称。我这样做是从API接收数据的,但是我可以在控制台中登录时却无法在屏幕上呈现数据。
为此,我使用了三个分开的文件。App.js,Form.js(用于提交条款)和weather.js(用于API配置)。
我猜测我需要映射接收到的数据,但尚未成功。
class App extends React.Component {
state = {
city: null,
}
getWeather = async city => {
const response = await weather.get('/forecast', {
params: {
q: city
}
});
this.setState({
city: response.name,
})
console.log(city); <--- This works
}
render() {
return (
<div>
<Form loadWeather={this.getWeather} />
<p>{this.state.city}</p> <--- This doesn't work
</div>
);
}
}
Run Code Online (Sandbox Code Playgroud)
class Form extends React.Component {
state = { term: '' };
onFormSubmit = (event) => {
event.preventDefault();
this.props.loadWeather(this.state.term);
this.refs.textInput.value = ''; …
Run Code Online (Sandbox Code Playgroud)