我无法在我的新项目中激活 venv(也是 Python 新手),
如果我这样做python --version:Python 3.7.2
我在我的编辑器(vs 代码)中使用“$ python -m venv ./venv”创建了 venv。
现在激活是我遇到问题的地方,
尝试 1:
$ ./venv/Scripts/activate.bat
error : 'C:\Users\name' is not recognized as an internal or external command, operable program or batch file.
The system cannot find the path specified.
Run Code Online (Sandbox Code Playgroud)
我的用户名由 2 个名称“名称和名称”格式化,它们之间有空格!那是问题吗?它只显示名字而不显示第二个。
尝试 2:
$ C:\Users/name & name/Desktop/ProjectFolder/venv/Scripts/activate.bat
error:
[1] 15160
bash: C:Users/name: No such file or directory
bash: name/Desktop/ProjectFolder/venv/Scripts/activate.bat: No such file or directory
[1]+ Exit 127 C:\Users/name
Run Code Online (Sandbox Code Playgroud) 我是React的新手,仍然在学习。我正在尝试将数据从孩子传递给祖父母。到目前为止,我和父母接触,被困住了。
子组件:
export class Child extends React.Component{
constructor(props) {
super(props);
this.state= {
counterChild: 5
}
}
render() {
return(
<div>
<span>Child: {this.state.counterChild}</span><br />
<button onClick={this.props.data(this.state.counterChild)}>Click me</button>
</div>
);
}
}
Run Code Online (Sandbox Code Playgroud)
父组件:
export default class Parent extends React.Component{
constructor(props){
super(props);
this.state= {
counterParent: 0
}
}
updateParent(value) {
return() => {
this.setState({
counterParent: value
});
}
}
componentWillMount(){
this.props.data(this.state.counterParent)
}
render(){
return(
<div>
<span>Parent: {this.state.counterParent}</span>
<Child data={this.updateParent.bind(this)}/>
</div>
);
}
}
Run Code Online (Sandbox Code Playgroud)
在子组件中,我使用按钮,在这里我想我必须使用componentWillMount才能发送给祖父母..但它没有达到
祖父母组件:
export default class Grandparent extends React.Component{
constructor(props){
super(props); …Run Code Online (Sandbox Code Playgroud) 我不知道我哪里做错了。我无法将数据从孩子发送给父母。这里有什么问题?如何从孩子那里获取状态并发送到父状态?
这是子组件
import React from 'react';
export class Child extends React.Component{
constructor(props) {
super(props);
this.state= {
counter2: 5
}
}
render() {
return(
<div>
<button onClick={this.props.data}>Click me</button><span>{this.state.counter2}</span>
</div>
);
}
}
export default Child;
Run Code Online (Sandbox Code Playgroud)
我想更新父组件中的状态
import React from 'react';
import {Child} from './Child';
export default class Parent extends React.Component{
constructor(props){
super(props);
this.state= {
counter: 0
}
}
update(){
this.setState({
counter: this.props.state.counter2
});
}
render(){
return(
<div>
<span>{this.state.counter}</span>
<Child data={this.update.bind(this)}/>
</div>
);
}
}
Run Code Online (Sandbox Code Playgroud)
但我有一个错误:× TypeError:无法读取未定义的属性“计数器”?
我不明白我做错了什么!
谢谢
我尝试将数组导入父组件并将该数据作为道具发送给他的孩子
import Seed from './const/Seed';
export default class ProductList extends React.Component{
render() {
const product = Seed.products[0]
return(
<div>
<Product
id = {product.id}
title = {product.title}
/>
</div>
);
}
}
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:TypeError:无法读取未定义的属性“ 0”
也许我没有以正确的方式格式化?还是有办法在其他文件上声明const?
export default class Seed extends React.Component{
render(){
const products = [
{
id: 1,
title: 'Yellow Pail',
},
{
id: 2,
title: 'Green Pail',
}
]
return products
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢