【发布时间】:2025-12-27 20:05:10
【问题描述】:
我是 Reactjs 的初学者并尝试学习和改进,这里我的代码在 test h1 > 的位置,在此代码下应该出现像这样 1:1 1:2 1:3 的数字,但是css 似乎无法使用它,我得到数字但没有 css,我也没有收到任何错误消息......这里有什么问题吗?代码:
import React, { Component } from 'react'
class Button extends Component {
state = {}
button = () => {
const proxyurl = "https://cors-anywhere.herokuapp.com/";
const url = "http://*****.*****.com/numbers.txt";
fetch(proxyurl + url)
.then(response => response.text())
.then(contents => document.write(contents))
}
render() {
return (
<div >
<h1>test</h1>
<div style={{ color: 'red' }}>{this.button()}
</div>
</div >
);
}
}
export default Button;
css:
body {
background: url('***.png');
color:red;
margin:50px 0;
padding:0px;
text-align:center;
}
#root {
white-space: pre;
}
【问题讨论】:
-
知道这里有什么问题吗?
-
您期望什么结果,什么不起作用?
-
@Anarion css 根本不工作,正在抓取工作
-
你的意思是你的CSS没有附加到页面上? CSS 不能“不起作用”,它可能不存在于页面上,或者选择器可能错误
标签: javascript html css reactjs jsx