小编jt2*_*t25的帖子

HTML5 Canvas Fibonacci螺旋

目前我正在看这个代码,但无法弄清楚是什么问题.

 function fibNumbers() {
    return [0, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
}

function continiusFib(a) {
    var b = fibNumbers(),
    c = Math.floor(a),
    d = Math.ceil(a);
    if (d >= b.length)
        return null;
    a = Math.pow(a - c, 1.15);
    return b[c] + (b[d] - b[c]) * a
}

function drawSpiral(pointA, pointB) {
    var b = pointA;
    var c = pointB;
    ctx.translate(b.x, b.y);
    b = Math.sqrt(((c.x - b.x) * (c.x - b.x)) + ((c.y - b.y) * (c.y …
Run Code Online (Sandbox Code Playgroud)

javascript math jquery html5 canvas

17
推荐指数
2
解决办法
3164
查看次数

如何在html画布中制作平行线

我有这些条件:

  1. 创建点A,B和C.
  2. 点A到点B将创建一条线.
  3. 根据A,B和C点的位置创建平行线(参见下图).
  4. 如果移动A点,线条也会移动,但B点和C点保持在各自的位置.
  5. 它们可以在任何位置移动.

我想要的是创造这个:

在此输入图像描述

javascript jquery html5 html5-canvas

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

在 Create React App Typescript 中未读取 SetupProxy 文件

CRA --template typescriptsetupProxy.js文件中使用了这段代码

const { createProxyMiddleware } = require('http-proxy-middleware');

module.exports = function (app) {
  app.use(
    '/user/try',
    createProxyMiddleware({
      target: 'http://localhost:8002',
      changeOrigin: true,
    })
  );
};
Run Code Online (Sandbox Code Playgroud)

但问题是setupProxy.js文件被完全忽略导致我的请求失败。

我知道我可以使用"proxy": "http://localhost:8002"inpackage.json但它不接受多个代理。

为了进一步测试,我还创建了一个新的CRA没有打字稿,突然它可以使用上面相同的代码。

有没有办法setupProxy.jsCRA 打字稿中工作?

javascript typescript reactjs create-react-app

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

参考错误:初始化前无法访问存储

我有这个 store/index.ts

export const storeRedux = createStore(
  persistReducer(ReduxPersistConfig, rootReducer),
  composeEnhancers(applyMiddleware(sagaMiddleware))
);
Run Code Online (Sandbox Code Playgroud)

并使用此实现来访问组件外部的令牌

//api.ts

import axios from 'axios';
import { storeRedux } from 'store';

let token;

const listener = () => {
  token = storeRedux.getState().user.token;
};

storeRedux.subscribe(listener);

// console.log(() => getAPI());

export default axios.create({
  baseURL: 'http://localhost:5000/api/security',
  headers: {
    Authorization: `Bearer ${token}`,
  },
 
});
Run Code Online (Sandbox Code Playgroud)

如果我添加一个 setTimeout 来包装,getState()那么一切都会好起来的。

是否有其他解决方案,因为商店已经像本文中那样分开了

javascript typescript reactjs react-redux axios

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

如何在C#中删除URL中的www、http/https等字符串

例如我有这个字符串

http://www.merriam-webster.com/dictionary/sample
Run Code Online (Sandbox Code Playgroud)

我想要的是只返回merriam-webster.com我打算使用的,.Replace()但我认为这个问题有更好的方法。

c# string parsing

4
推荐指数
2
解决办法
5187
查看次数

在useEffect中调用Redux Action

我的目的是在内调用一个动作useEffect

const ShowTodos = (props) =>{
   useEffect(()=>{
    props.fetchTodos()
   },[])
} 
const mapStateToProps = (state)=>{
  return {
    todos:Object.values(state.todos),
    currentUserId:state.authenticate.userId
  }
}

export default connect(mapStateToProps,{fetchTodos})(ShowTodos)
Run Code Online (Sandbox Code Playgroud)

效果很好,但我收到警告

React Hook useEffect has a missing dependency: 'props'. Either include it or remove the dependency array  react-hooks/exhaustive-deps.
Run Code Online (Sandbox Code Playgroud)

但是,如果要props在我的参数中添加第二个参数,useEffects则它将无限运行。

我在这里的第一个解决方法是使用,useRef但它似乎总是会重新渲染,因此再次重新设置useRef,我认为这在优化方面并不好。

const ref = useRef();
  ref.current = props;
  console.log(ref)


  useEffect(()=>{
  ref.current.fetchTodos()
  },[])
Run Code Online (Sandbox Code Playgroud)

这里还有其他解决方法吗?

reactjs redux react-hooks

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

将数组中每个对象的值(如果为 0)更改为 null

我有这个例如:

const sample = [
  { id: 1, val1: 0, val4: 10 },
  { id: 10, val1: 1, val4: 10, val19: 0, val29: 0 },
  { id: 11, val1: 0, val4: 0, val19: 0, val29: 10 },
];
Run Code Online (Sandbox Code Playgroud)

我想将每个 0 值更改为 null

const sample = [
  { id: 1, val1: null, val4: 10 },
  { id: 10, val1: 1, val4: 10, val19: null, val29: null },
  { id: 11, val1: null, any: null, sample: null, val29: 10 },
];
Run Code Online (Sandbox Code Playgroud)

我知道我需要使用, …

javascript typescript ecmascript-6

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

如何将对象数组重新映射到新数组中

我有这个初始数组:

const initialData = [
  {
    day: 1,
    values: [
      {
        name: 'Roger',
        score: 90,
      },
      {
        name: 'Kevin',
        score: 88,
      },
      {
        name: 'Steve',
        score: 80,
      },
    ],
  },
  {
    day: 2,
    values: [
      {
        name: 'Roger',
        score: 70,
      },
      {
        name: 'Michael',
        score: 88,
      },
    ],
  },
  {
    day: 3,
    values: [
      {
        name: 'Steve',
        score: 97,
      },
    ],
  },
];
Run Code Online (Sandbox Code Playgroud)

要转换为:

const result = [
  {
    name: 'Roger',
    scores: [90, 70, null],
  },
  {
    name: 'Kevin',
    scores: …
Run Code Online (Sandbox Code Playgroud)

javascript typescript ecmascript-6

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

React 中的多个 Suspense 声明

例如我有这样的声明:

场景一:

const ComponentA = lazy(() => import('pages/ComponentA'));
const ComponentB = lazy(() => import('pages/ComponentB'));

<Router>
  <Switch>
     <Suspense fallback={'loading...'}>
       <Route path="/A" component={ComponentA} exact/>
       <Route path="/B" component={ComponentB} exact/> 
     </Suspense>
  </Switch>
</Router>
Run Code Online (Sandbox Code Playgroud)

如果 的加载依赖性仅为ComponentA1,则这种情况就很好。

但对于场景 2:如果我有多重依赖怎么办ComponentA

代码2

import Dependency1 from 'component/dependency1';
import Dependency2 from 'component/dependency2';

const ComponentA = () => {
   return (
     <div>
       <Dependency1/>
       <Dependency2/>
     </div>
   );
}
Run Code Online (Sandbox Code Playgroud)

可以将每个依赖项的 Suspense 声明分开吗?像这样:

代码3

 const Dependency1 = lazy(() => import('component/dependency1'));
 const Dependency2 = lazy(() => import('component/dependency2'));

 const ComponentA = () …
Run Code Online (Sandbox Code Playgroud)

javascript typescript reactjs react-hooks react-suspense

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