我有一个相对简单的问题,试图将内联脚本添加到React组件.到目前为止我所拥有的:
'use strict';
import '../../styles/pages/people.scss';
import React, { Component } from 'react';
import DocumentTitle from 'react-document-title';
import { prefix } from '../../core/util';
export default class extends Component {
render() {
return (
<DocumentTitle title="People">
<article className={[prefix('people'), prefix('people', 'index')].join(' ')}>
<h1 className="tk-brandon-grotesque">People</h1>
<script src="https://use.typekit.net/foobar.js"></script>
<script dangerouslySetInnerHTML={{__html: 'try{Typekit.load({ async: true });}catch(e){}'}}></script>
</article>
</DocumentTitle>
);
}
};
Run Code Online (Sandbox Code Playgroud)
我也尝试过:
<script src="https://use.typekit.net/foobar.js"></script>
<script>try{Typekit.load({ async: true });}catch(e){}</script>
Run Code Online (Sandbox Code Playgroud)
这两种方法似乎都没有执行所需的脚本.我猜这是一件我想念的简单事.有人可以帮忙吗?
PS:忽略foobar,我有一个真正的ID实际上在使用,我不想分享.
我遇到了一个我不完全理解的问题.我觉得有可能是我没有掌握的概念,可以优化的代码,以及可能出现的错误.
大大简化整体流程:
这是原始请求(#1):
await Store.get(Constants.Contentful.ENTRY, Contentful[page.file])
Run Code Online (Sandbox Code Playgroud)
Store.get表示为:
async get(type, id) {
return await this._get(type, id);
}
Run Code Online (Sandbox Code Playgroud)
哪个电话:
_get(type, id) {
return new Promise(async (resolve, reject) => {
var data = _json[id] = _json[id] || await this._api(type, id);
console.log(data)
if(isAsset(data)) {
resolve(data);
} else if(isEntry(data)) {
await this._scan(data);
resolve(data);
} else {
const error = 'Response is not entry/asset.';
console.log(error);
reject(error);
}
});
}
Run Code Online (Sandbox Code Playgroud)
API调用是:
_api(type, id) {
return new Promise((resolve, reject) => {
Request('http://cdn.contentful.com/spaces/' + Constants.Contentful.SPACE …
Run Code Online (Sandbox Code Playgroud) 有没有办法将数据/ aria属性的对象传递给元素?
我试过了:
div(data={foo:'bar'})
div(data={foo='bar'})
div&attributes({aria:{foo:'bar'}})
Run Code Online (Sandbox Code Playgroud)
但是这些都不输出所需的属性符号。对象文字的第一和第三位在基础数据/ aria属性中。第二个是语法错误。
我可以找到该作品的唯一方法是:
div(data-foo='bar')
div&attributes({'aria-foo':'bar'})
Run Code Online (Sandbox Code Playgroud) 在 Chrome 上,我可以通过查看window.visualViewport.scale
它在 Safari 上可用来获得视口比例,但是,似乎window.visualViewport
没有在 iOS上的旧版本Safari 上定义。
有什么解决方法吗?
我正在使用react-virtualized来获取一长串(1000 多个)项目列表以供选择。我正在尝试设置一个端到端测试,需要单击当前未渲染的元素之一。
通常,我会简单地使用类似的东西:
await t.click(
ReactSelector('ListPage')
.findReact('ListItem')
.nth(873) // or .withText(...) or .withProps(...)
)
Run Code Online (Sandbox Code Playgroud)
但由于只渲染了 s 的一小部分ListItem
,TestCafe 无法找到所需的元素。
我一直在试图弄清楚如何使用 TestCafe 的ClientFunction滚动列表容器,以便ListItem
呈现所需的内容。
但是,我遇到了一些问题:
Selector
并ClientFunction
修改DOM元素的scrollTop?或者我是否必须直接通过 DOM 重新查询元素?ListItem
s 的高度不同,滚动位置不是索引x项目高度的简单计算。如何在此函数中不断更新/滚动,直到所需的内容Selector
可见?automated-tests typescript reactjs react-virtualized testcafe
javascript ×3
reactjs ×3
node.js ×2
babeljs ×1
ecmascript-6 ×1
ios ×1
mobile ×1
pug ×1
react-jsx ×1
testcafe ×1
typescript ×1
viewport ×1
webpack ×1
window ×1