我正在使用React的最新版本(16.6)和react-router
(4.3.1)并尝试使用代码分割React.Suspense
.
虽然我的路由工作正常并且代码确实分裂成了几个动态加载的bundle,但我收到的警告是不返回一个函数,而是一个对象Route
.我的代码:
import React, { lazy, Suspense } from 'react';
import { Switch, Route, withRouter } from 'react-router-dom';
import Loading from 'common/Loading';
const Prime = lazy(() => import('modules/Prime'));
const Demo = lazy(() => import('modules/Demo'));
const App = () => (
<Suspense fallback={<Loading>Loading...</Loading>}>
<Switch>
<Route path="/" component={Prime} exact />
<Route path="/demo" component={Demo} />
</Switch>
</Suspense>
);
export default withRouter(App);
Run Code Online (Sandbox Code Playgroud)
控制台警告如下:
Warning: Failed prop type: Invalid prop `component` of type `object` supplied to `Route`, expected `function`. …
dynamic-import reactjs react-router react-router-v4 react-16
伙计们,我正在努力做到以下几点.我有一个名为'specialLevels'的数组(NSArray),该数组如下所示:
specialLevels = @[@2, @4, @6, @9];
Run Code Online (Sandbox Code Playgroud)
这应该是一个int数组.我也得到了int'urrentLevel'(基本int无对象).
我想检查currentLevel是否在特殊级别的de数组中.我知道方法'containsObject'存在,但这在我的情况下不起作用.
在这种情况下,你们会建议做什么?
所以我想到了这一点,但感觉有点奇怪:
if ([specialLevels containsObject:[NSNumber numberWithInt:currentLevel]]) {
// other code in here
}
Run Code Online (Sandbox Code Playgroud) 我目前正在使用带有Suspense和Lazy的React 16来拆分我的代码库。虽然我想预加载组件。
在下面的示例中,我有两条路线。挂载Demo
后有Prime
没有预加载的方法?我尝试componentDidMount
在Prime
页面的中创建另一个动态导入,但React.lazy
似乎并没有获得与下面的动态导入相同的文件。
import React, { lazy, Suspense } from 'react';
import { Switch, Route, withRouter } from 'react-router-dom';
import GlobalStyle from 'styles';
import Loading from 'common/Loading';
const Prime = lazy(() => import(/* webpackChunkName: "Prime" */'modules/Prime'));
const Demo = lazy(() => import(/* webpackChunkName: "Demo" */'modules/Demo'));
const App = () => (
<main>
<GlobalStyle />
<Suspense fallback={<Loading>Loading...</Loading>}>
<Switch>
<Route path="/" component={Prime} exact />
<Route path="/demo" component={Demo} />
</Switch>
</Suspense>
</main>
); …
Run Code Online (Sandbox Code Playgroud) :after
是否有可能在其父元素的背景后面 获取 CSS 伪元素?
的背景:after
包含与父元素的背景相同的尺寸。所以目前看起来是这样的:
但我希望红色背景 ( :after
) 位于父元素后面。所以我添加了position: relative
父元素和absolute
伪元素。
试图存档这个我使用了这段代码:
.btn {
position: relative;
display: inline-block;
padding: .8rem 1rem;
font-size: 1rem;
background: #000;
}
.btn:after {
position: absolute;
bottom: -0.3rem; right: -0.3rem;
z-index: -1;
width: 100%; height: 100%;
content:'';
background: red;
}
Run Code Online (Sandbox Code Playgroud)
<a href="" class="btn">
This is my button
</a>
Run Code Online (Sandbox Code Playgroud)
奇怪的是上面的代码片段就像魅力一样。但在我的实时示例中,显示的代码与本主题中的图像完全相同。有人知道实时站点出了什么问题吗?
使用 React Router v6 我想渲染回调页面。尽管我无法从屏幕中的 element 属性获取输出。我只从 out 获取输出,并且回调页面始终是空白屏幕或 404。新的 React Router 缺少什么?
const App: React.FC = () => (
<>
<GlobalStyle />
<Suspense fallback={<Loading fullScreen />}>
<Routes>
<Route path="/" element={<PrivateRoute component={Home} />} />
<Route path="/login" element={<PublicRoute component={Login} />} />
<Route path="/auth/*" element={<p>auth</p>}>
<Route path="callback" element={<p>callback</p>} />
</Route>
</Routes>
</Suspense>
</>
);
Run Code Online (Sandbox Code Playgroud)
const App: React.FC = () => (
<>
<GlobalStyle />
<Suspense fallback={<Loading fullScreen />}>
<Routes>
<Route path="/" element={<PrivateRoute component={Home} />} />
<Route path="/login" element={<PublicRoute component={Login} />} />
<Route …
Run Code Online (Sandbox Code Playgroud) 目前,我正在尝试使用Samsung Tab A构建Web应用程序。我认为该设备将支持Service Workers,原因是以下“我可以使用”说需要运行Android的Chrome for Android 55。
平板电脑正在运行Android 6.0.1(无可用更新)和Chrome 55.0.2,但不幸的是,当运行下面显示的代码时,会弹出“ no sw”警报。SW在台式机上的Chrome(Mac OS)上运行良好)。
if('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js').then((registration) => {
alert('sw');
console.log('ServiceWorker successful, scope: ', registration.scope);
}).catch((err) => {
alert('no sw');
console.log('ServiceWorker failed: ', err);
});
}
Run Code Online (Sandbox Code Playgroud)
我是在做错什么,还是无法在这种平板电脑上运行SW?如果Chrome 55还不够,还需要什么?我认为有关此主题的信息有所欠缺,因为我找不到有关此问题的答案.. :(
提前致谢!
编辑:我已经启用了多个标志,chrome://flags
但没有成功。
我正在使用Nodemailer在NodeJS / Express服务器中发送邮件。我不想直接发送邮件,而是要等待20分钟才能发送邮件。我认为这比直接发送邮件更具个性。
但是我不知道如何实现这一目标。我想我不需要像这样的NodeCron程序包之类的NodeJS cronjob之类的东西,还是吗?
router.post('/', (req, res) => {
const transporter = nodemailer.createTransport(smtpTransport({
host: 'smtp.gmail.com',
port: 465,
auth: {
user: 'noreply@domain.nl',
pass: 'pass123'
}
}));
const mailOptions = {
from: `"${req.body.name}" <${req.body.email}>`,
to: 'info@domain.nl',
subject: 'Form send',
html: `Content`
};
transporter.sendMail(mailOptions, (error, info) => {
if (error) res.status(500).json({ responseText: error });
res.status(200).json({ responseText: 'Message send!' });
});
}
});
Run Code Online (Sandbox Code Playgroud)
我的路由器如下图所示。因此,如果调用post,我希望此请求等待20分钟。我不想执行一次cronjob,而是只执行一次,但有一点延迟。有关如何执行此操作的任何建议?
我有一个带有视频元素和掩码图像的容器,如下所示:
<div id="container">
<img id="mask" src="/images/mask.png" width="1078" height="1508" />
<video autoplay="" id="video"></video>
</div>
Run Code Online (Sandbox Code Playgroud)
你们可以看到掩模图像的宽度为1078px,高度为1508px.视频元素的宽度也是1078像素,但高度仅为807像素(不必更长).
canvas元素具有相同的宽度和高度.当我尝试拍摄视频的快照并将该快照和蒙版图像的副本绘制到画布时,两个元素都在画布边界之外被拉伸.
var context = canvas.getContext('2d');
// Draw video
context.drawImage(video, 0, 0);
// Get mask image and draw mask
maskObj.src = document.getElementById("mask").src;
context.drawImage(maskObj, 0, 0);
Run Code Online (Sandbox Code Playgroud)
我知道我可以通过drawImage()
函数传递更多参数,但我不知道其他参数究竟是什么.该文章说,你可以只传递宽度和高度为一个整数.但如果我做以下事情:
context.drawImage(video, 0, 0, 1078, 807);
context.drawImage(maskObj, 0, 0, 1078, 1508);
Run Code Online (Sandbox Code Playgroud)
它仍然在画布边界之外绘制元素.无法真正找出我做错了所以所有的帮助表示赞赏.
例;
在我的故事板中,我有一个表格视图.我正在使用从JSON文件加载的数据(在viewDidLoad中加载)填充该表视图.
在我的UITableView中,我确实将"Prototype Cells"设置为1,因此我可以轻松选择附件.我的Prototype Cell有一个Seque到一个新视图,需要显示所选项目的详细信息.
我用以下方式以编程方式填充我的单元格:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *videoTableIdentifier = @"VideoCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:videoTableIdentifier];
if (cell == nil)
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:videoTableIdentifier];
UILabel * title = [[UILabel alloc] initWithFrame:CGRectMake(40,5, 240,20)];
[cell addSubview:title];
[title setText:[[videos objectAtIndex:indexPath.row] objectForKey:@"title"]];
UILabel * detail = [[UILabel alloc] initWithFrame:CGRectMake(40,28, 100,10)];
[cell addSubview:detail];
[detail setText:[NSString stringWithFormat:@"Year: %@", [[videos objectAtIndex:indexPath.row] objectForKey:@"year"]]];
[cell addSubview:[[UIImageView alloc] initWithImage:[UIImage imageNamed:[[videos objectAtIndex:indexPath.row] objectForKey:@"image"]]]];
return cell;
}
Run Code Online (Sandbox Code Playgroud)
当我开始滚动时,会发生以下情况:
所以我开始寻找解决方案,发现我必须设置:dequeueReusableCellWithIdentifier:videoTableIdentifier
"nil".
虽然我这样做了,但这解决了我的问题,但现在我的Prototype …
javascript ×4
reactjs ×3
css ×2
objective-c ×2
react-16 ×2
react-router ×2
android ×1
arrays ×1
behind ×1
border ×1
canvas ×1
dimensions ×1
drawimage ×1
express ×1
image ×1
int ×1
ios ×1
node.js ×1
nodemailer ×1
overlapping ×1
preload ×1
scroll ×1
uitableview ×1
z-index ×1