小编Ves*_*smy的帖子

如何在iOS中将LaunchScreen.xib的线性渐变设置为背景

有没有办法在iOS中将LaunchScreen.xib的线性渐变设置为背景?有点像background="linear-gradient(#000000, #123456)"

<view contentMode="scaleToFill" background="...">
    <rect key="frame" width="753" height="867"/>
</view>
Run Code Online (Sandbox Code Playgroud)

background linear-gradients xib ios launch-screen

9
推荐指数
2
解决办法
8196
查看次数

循环中的ES6导入

有没有办法在ES6中使用for-of-loop(或其他循环)导入和导出多个文件?

const moduleNames = ['NumberUtils', 'StringUtils', 'ArrayUtils', 'MyModule', 'AnotherModule', 'BaseModule']

let modules = {}

for (const moduleName of moduleNames) {
    import module from './' + moduleName
    modules.moduleName = module
}

export modules
Run Code Online (Sandbox Code Playgroud)

没有循环我必须写:

import NumberUtils from './NumberUtils'
import StringUtils from './StringUtils'
import ArrayUtils from './ArrayUtils'
import MyModule from './MyModule'
import AnotherModule from './AnotherModule'
import BaseModule from './BaseModule'

export {
    NumberUtils,
    StringUtils
    ArrayUtils
    MyModule
    AnotherModule
    BaseModule
}
Run Code Online (Sandbox Code Playgroud)

javascript import loops ecmascript-6

9
推荐指数
3
解决办法
5779
查看次数

箭头与ES6类中的经典方法

有没有理由编写ES6方法的经典语法?

class MyClass {

    myMethod() {
        this.myVariable++;
    }

}
Run Code Online (Sandbox Code Playgroud)

当我myMethod()在某些事件上使用回调时,我必须写这样的东西(在JSX中):

// Anonymous function.
onClick={() => { this.myMethod(); }}

// Or bind this.
onClick={this.myMethod.bind(this)}
Run Code Online (Sandbox Code Playgroud)

但是如果我将方法声明为箭头函数:

class MyClass {

    myMethod = () => {
        this.myVariable++;
    }

}
Run Code Online (Sandbox Code Playgroud)

我只能写(在JSX中):

onClick={this.myMethod}
Run Code Online (Sandbox Code Playgroud)

javascript jsx ecmascript-6 arrow-functions ecmascript-next

6
推荐指数
1
解决办法
1288
查看次数

我怎么能使用text-align-last,除非我只有一行文字?

我想将文本与中心对齐,但最后一行在左边:

section {
    text-align: center;
    text-align-last: left;
}
Run Code Online (Sandbox Code Playgroud)

它运作良好,但如果只有一条线怎么办?在这种情况下,我想将文本与中心对齐,这不起作用,因为第一行也是最后一行.对于只有多行文本或第一行选择器(非伪元素:first-line)的元素,是否有任何选择器?

实例:

section {
  text-align: center;
  text-align-last: left;
  width: 300px;
}
Run Code Online (Sandbox Code Playgroud)
<strong>This works:</strong>
<section>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam aliquam turpis consectetur diam fringilla, vel ultrices sapien bibendum. Maecenas pulvinar in nisl at mattis. Duis nisi risus, rhoncus sit amet ornare malesuada.</section>

<strong>Next line should be centered (something like text-align-first?):</strong>
<section>Lorem ipsum dolor sit amet.</section>
Run Code Online (Sandbox Code Playgroud)

css text-align

5
推荐指数
2
解决办法
774
查看次数

Microsoft Edge悬停错误

我在Microsoft Edge中有一个错误.<div>悬停期间transform: scale(1.5);transition: transform 1s;.但是当你将光标移动到div时,等待1秒,移出然后快速移动到div,div的比例被打破并且转换消失.有没有办法解决这个问题?这是小提琴.

div {
  background-color: green;
  transition: transform 1s;
  height: 100px;
  width: 100px;
}

div:hover {
  transform: scale(1.5);
}
Run Code Online (Sandbox Code Playgroud)
<div></div>
Run Code Online (Sandbox Code Playgroud)

html css transition hover microsoft-edge

5
推荐指数
1
解决办法
2845
查看次数

自己的 utils 文件的反应结构

结构 React 应用程序有什么最佳实践吗?有时,我需要移动通用函数来分隔文件。但是哪里?它不是 node_module。

  • .gitignore
  • .git
  • 包.json
  • 节点模块
  • 源文件
    • 成分
    • 意见
    • 减速机
    • 行动
    • 实用程序?这是我的 utils 文件夹。
      1. DateUtils.js
      2. 字符串实用程序
      3. NumberUtils.js

另一种方法是创建包含所有实用程序的基本反应组件。所有其他 react 文件都将是该组件的子组件。

class MyBaseComponent extends React.Component {

    dateUtilsMethod() {
       ...
    }

    stringUtilsMethod(myString) {
        ...
    }

}

class MainPageView extends MyBaseComponent { ... }
Run Code Online (Sandbox Code Playgroud)

最好的解决方案是什么?

javascript project-structure reactjs

4
推荐指数
1
解决办法
4671
查看次数

Babylon.js 去除球体的光反射

如何在 Babylon.js 中消除球体的(点)光反射?

// Point light.
const light = new BABYLON.PointLight('myLight', new BABYLON.Vector3(0, 1, 0), scene)

// Sphere with size 100.
const newBox = BABYLON.Mesh.CreateSphere('mySphere', 64, 100, scene)
Run Code Online (Sandbox Code Playgroud)

我想照亮一半球体,但不要在红色圆圈中反射:

在此输入图像描述

javascript light babylonjs

3
推荐指数
1
解决办法
2184
查看次数

预期数组但在Jest中收到了数组

我在Jest中创建了单元(异步)测试。但是当我从服务器得到响应时:

[
    {
        name: "My name"
    },
    {
        name: "Another name"
    }
]
Run Code Online (Sandbox Code Playgroud)

并测试:

test('Response from server', () => {
    get('my-url').end(error, response) => {
        expect(response.body).toBe(expect.any(Array))
    }
})
Run Code Online (Sandbox Code Playgroud)

发生一些错误:

Comparing two different types of values. Expected Array but received array.
Run Code Online (Sandbox Code Playgroud)

当我使用时,它正在工作expect(response.body).any(Array)。但是有什么解决办法expect.toBe()吗?

javascript arrays reactjs jestjs

1
推荐指数
1
解决办法
1999
查看次数