我正在尝试在图像上设置线性渐变背景,我的代码在 Chrome 中有效,但在 Safari 中无效。这是我的代码的完整示例:
HTML:
<div>
<img src="./assets/51a-front-img.png" draggable="false"/>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS:
div:after{
content: '\A';
position: absolute;
width: 100%;
height: 100%;
top:0;
background: rgba(0,0,0,0.5);
background: -moz-linear-gradient(top, rgba(0,0,0,0.5) 0%,rgba(0,0,0,0.7) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(0,0,0,0.5)), color-stop(100%,rgba(0,0,0,0.7))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(0,0,0,0.5) 0%,rgba(0,0,0,0.7) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, rgba(0,0,0,0.5) 0%,rgba(0,0,0,0.7) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, rgba(0,0,0,0.5) 0%,rgba(0,0,0,0.7) 100%); /* IE10+ */
background: linear-gradient(to bottom, rgba(0,0,0,0.5) 0%,rgba(0,0,0,0.7) 100%); /* W3C */
}
img { …Run Code Online (Sandbox Code Playgroud) 我在后端使用Hapi,在前端使用React.我的webpack配置指定以下内容:
module: {
loaders: [
{ test: /\.(ttf|otf|eot|svg|woff(2)?)(\?[a-z0-9]+)?$/, loader: 'file-loader?name=public/ozregular.otf'}
]
},
Run Code Online (Sandbox Code Playgroud)
CSS:
@font-face {
font-family: OzRegular;
src: url(/ozregular.otf) format("opentype");
}
Run Code Online (Sandbox Code Playgroud)
该字体在Safari中有效但在Chrome中我遇到以下错误:

在Firefox中我得到这些错误:

我已经尝试了以下stackoverflow问题的答案但它似乎没有工作:Webpack"OTS解析错误"加载字体
有没有人有任何想法如何让字体在Chrome和Firefox中运行?
我正在尝试使用ajv-keywords中的 if/then/else关键字创建条件验证,但是我在浏览器控制台中收到以下错误:"未捕获错误:关键字如果已定义".
我究竟做错了什么?
import * as ajvErrors from 'ajv-errors';
import * as ajvKeywords from 'ajv-keywords';
const ajv = new Ajv({ allErrors: true, jsonPointers: true });
ajvErrors(ajv);
ajvKeywords(ajv);
const schema = {
if: {
properties: {
fundraiser: { type: 'string' }
}
},
then: {
required: ['title'],
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用别名在我before和beforeEach钩子之间共享值。如果我的值是字符串,则当前有效,但是当值是对象时,别名仅在第一个测试中定义,此后的每个测试this.user在我的beforeEach挂钩中均未定义。如何在测试之间共享作为对象的值?
这是我的代码:
before(function() {
const email = `test+${uuidv4()}@example.com`;
cy
.register(email)
.its("body.data.user")
.as("user");
});
beforeEach(function() {
console.log("this.user", this.user); // This is undefined in every test except the first
});
Run Code Online (Sandbox Code Playgroud) 我正在使用react-testing-library并且我有一个自定义渲染:
const customRender = (node, ...options) => {
return render(
<ThemeProvider theme={Theme}>
<MemoryRouter>{node}</MemoryRouter>
</ThemeProvider>,
...options
);
};
Run Code Online (Sandbox Code Playgroud)
我可以在我的测试中成功使用它render,但不能用于 a rerender:
test("shows content once data has loaded", () => {
const { queryByTestId, rerender, debug } = render(
<ConnectAccount
currentUser={{
loading: true
}}
/>
);
expect(queryByTestId("content")).toBeNull();
rerender(
<ConnectAccount
currentUser={{
user: {
name: "Test User"
}
}}
/>
);
debug();
});
Run Code Online (Sandbox Code Playgroud)
我收到一个TypeError: Cannot read property 'black' of undefined错误rerender。有没有办法让重新渲染使用自定义渲染,这样我就不必将每个重新渲染都包装在 中ThemeProvider?