我只是有一个小问题.
为什么undefined == undefined返回true,但是undefined >= undefined是false?
undefined等于undefined.
但它不等于或更大?
function App(){
const cntEl:any = React.useRef(null); // I don't know what type should be here.
React.useEffect(()=>{
if(cntEl.current){ cuntEl.current.start() }
}, []);
return <Countdown ref={cntEl} />
}
const Countdown = React.forwardRef((props,ref) => {
React.useImperativeHandle(ref, ()=>({
start() {
alert('Start');
}
});
return <div>Countdown</div>
});
Run Code Online (Sandbox Code Playgroud)
我尝试使用ref和在父组件中使用子方法React.useImperativeHandle()。
它运作良好。
但我不满意,因为const cntEl:any。
我相信有很多方法可以避免使用any我不知道的类型。
我只需要一个可以被替换的类型 type any。
已编辑
我可以看到(property) React.MutableRefObject<null>.current: null当我悬停在cntEl.current
我想在Amazon S3上托管我的 React 项目。
我正在开发它Next.js。
文件夹树如下所示。
pages
|- auth
| |- index.tsx
|- (...)
|- index.tsx
Run Code Online (Sandbox Code Playgroud)
我做到了
next build && next export
Run Code Online (Sandbox Code Playgroud)
构建和导出后,我期望它
out
|- _next
|- auth
| |- index.html /* I want another index.html */
|- (...)
|- index.html
|- static
Run Code Online (Sandbox Code Playgroud)
但我明白了,
|- _next
|- auth.html /*I need /auth/index.html*/
|- (...)
|- index.html
|- static
Run Code Online (Sandbox Code Playgroud)
我怎样才能实现呢。
先感谢您。
我想将我的nextjs项目构建为开发模式。
我试过喜欢它
包.json
{
...
"scripts": {
"dev": "next",
"build:dev": "set NODE_ENV=development & next build",
"build:prod": "set NODE_ENV=production & next build",
"start:dev": "set NODE_ENV=development & next start",
"start:prod": "set NODE_ENV=production & next start"
}
...
}
Run Code Online (Sandbox Code Playgroud)
下一个.config.js
module.exports = withSass({
env: {
baseUrl: process.env.NODE_ENV === "development" ? "devServerURL": "prodServerURL"
}
});
Run Code Online (Sandbox Code Playgroud)
但我无法实现我想要的。
所以,我尝试了一些改变。
包.json
"scripts": {
"dev": "next",
"build": "next build",
"start:dev": "set NODE_ENV=development & next start",
"start:prod": "set NODE_ENV=production & next start"
}
Run Code Online (Sandbox Code Playgroud)
但它也不起作用。
如何构建 …
我在使用时遇到这个错误 URLSearchParams
TypeError: url__WEBPACK_IMPORTED_MODULE_2__.URLSearchParams 不是构造函数
这就是我打电话的方式:
componentDidMount() {
const query = new URLSearchParams(this.props.location.search); // <- ERORR
const ingredients = {};
for (let param in query.entries()) {
// ['salad', '1']
ingredients[param[0]] = +param[1];
}
this.setState({ingredients : ingredients});
}
Run Code Online (Sandbox Code Playgroud)
我的 ReactJS 项目详情:
"dependencies": {
"axios": "^0.19.0",
"prop-types": "^15.7.2",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-router-dom": "^5.0.1",
"react-scripts": "3.0.1"
},
Run Code Online (Sandbox Code Playgroud) 我正在做一张桌子。
document.querySelector('table').addEventListener('click', (e) => {
console.log(e.target);
console.log(e.target.dataset.item);
})Run Code Online (Sandbox Code Playgroud)
td {
padding: 8px;
border: 1px solid black;
background-color: blue;
}
span {
background-color: red;
padding: 4px;
}Run Code Online (Sandbox Code Playgroud)
<table>
<tr>
<td data-item="item1"><span>1</span></td>
<td data-item="item2"><span>2</span></td>
<td data-item="item3"><span>3</span></td>
<td data-item="item4"><span>4</span></td>
<td data-item="item5"><span>5</span></td>
</tr>
</table>Run Code Online (Sandbox Code Playgroud)
当我点击蓝色部分时,我可以获得data-item属性。但是当我点击红色部分时,我不能。
我想修复它,如果我点击<span/>,<td/>我想从中获取data-item属性<td />。
我的代码:
export default (function () {
(...)
return {
open: () => {
(...)
},
close: () => {
(...)
},
get: () => {
(...)
}
}
})();
Run Code Online (Sandbox Code Playgroud)
我想这样调用close()in get()函数:
get: () => {
close();
}
Run Code Online (Sandbox Code Playgroud)
我尝试使用,this但它不起作用.
请给我一些建议.
先感谢您.
我正在开发一个 chrome 扩展。
我的一个 js 文件包含一个const对象。
我试图从js同一目录中的另一个文件导入它。
未捕获的语法错误:无法在模块外使用导入语句
在我的 attributes.js
export const key_attributes = {
'GK': ['Aerial', 'Agility', 'Handling', 'Reflexes'],
}
Run Code Online (Sandbox Code Playgroud)
我有上面的
在table.js,我有
import { key_attributes } from './attributes'
Run Code Online (Sandbox Code Playgroud)
这给了我
未捕获的语法错误:不能在模块外使用 import 语句`
有什么帮助吗?
$('#step1 input').change(function(){
$('#step1 input').each(function(){
console.log($(this).val());
});
});
$('#step2 input').change(function(){
console.log($(this).val());
});Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="step1">
Father's Details:    
<input name="hiddenelement" type="text" hidden="hidden" value="This is Father's name" />
<input name="First Name" type="text" placeholder="Enter First Name" />
</div>
<div id="step2">
Mother's Details:    
<input name="First Name" type="text" placeholder="Enter First Name" />
</div>Run Code Online (Sandbox Code Playgroud)
我有以下HTML:
<div id="step1">
Father's Details:    
<input name="hiddenelement" type="text" hidden="hidden" value="This is Father's name" />
<input name="First Name" type="text" placeholder="Enter First Name" />
</div>
<div id="step2">
Mother's Details:    
<input …Run Code Online (Sandbox Code Playgroud) 我在一个页面中有超过10个按钮,所以我只需要编写一次代码来悬停.因为这个我使用jQuery.请仔细检查我的代码.
$(document).ready(function(){
$('.button').hover(function(){
var bc=$(this).css('background-color');
var cl=$(this).css('color');
$(this).css('background-color',cl);
$(this).css('color',bc);
});
});Run Code Online (Sandbox Code Playgroud)
.button {
color: #FFFFFF;
text-align: center;
font-size: 22px;
height:70px;
width: 160px;
margin: 5px;
transition: all 0.5s;
margin-right:30px;
}
.button:hover{
transform: scale(1.1);
}Run Code Online (Sandbox Code Playgroud)
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js">
</script>
</head>
<body>
<button class="button" style="background-color: red;">Hover </button>
<button class="button" style="background-color: green;">Hover </button>
<button class="button" style="background-color: blue;">Hover </button>
</body>
</html>Run Code Online (Sandbox Code Playgroud)
如果我们连续悬停在按钮上意味着它会改变颜色,那么它是否可以通过单个悬停工作正常,如果有任何其他方法可以避免这种情况?颜色应保持不变.
javascript ×6
html ×3
reactjs ×3
jquery ×2
next.js ×2
css ×1
hover ×1
onclick ×1
react-router ×1
typescript ×1
undefined ×1