小编jim*_*mmy的帖子

如何从元素中得到"关键"?

我想在选择更改时获得选项的值和键.

我知道我可以onChangeevent.target.value函数中使用选项的简单值,但是如何获得键?

<select onChange={this.onChangeOption} value={country}>
    {countryOptions.map((item, key) =>
        <option key={key} value={item.value}>
            {item.name}
        </option>
    )}
</select>
Run Code Online (Sandbox Code Playgroud)

javascript reactjs

24
推荐指数
3
解决办法
4万
查看次数

如何在 dockerfile 中回答安装问题?

我尝试使用 dockerfile 安装一些东西。但是当我运行命令时,我必须回答如下问题:

进入

6

72

我的dockfile 如下所示,但似乎不起作用。

FROM ubuntu:latest
RUN apt-get update
RUN apt-get install -y expect
RUN apt-get -y install software-properties-common 
RUN apt-add-repository ppa:ondrej/php
expect “Press [ENTER] to continue or Ctrl-c to cancel adding it. ” { send “\n” }
RUN apt-get -y install php7.1 php7.1-fpm 
expect “Please select the geographic area in which you live. ” { send “6\n” }
expect “Please select the city or region corresponding to your time zone. ” { send “72\n” } …
Run Code Online (Sandbox Code Playgroud)

docker dockerfile

7
推荐指数
2
解决办法
5781
查看次数

如何在单元测试期间使用 vue-test-utils 和 jest 模拟 mixin?

我想测试Test.vue中的testMethod,但是testMethod使用了从App.js导入的mixin。

测试.vue

<script>
    export default {
        methods: {
            testMethod() {
                return 'get'+this.getTestMixin();
            }
        },
    };
</script>
Run Code Online (Sandbox Code Playgroud)

mixins/common.js

export default {
    methods: {
        getTestMixin() {
            return 'test';
        },
    },
};
Run Code Online (Sandbox Code Playgroud)

如何模拟mixin?我试图像下面这样模拟混合但失败了,知道我哪里做错了吗?

function getTestMixin() {
    return 'test';
}

const localVue = createLocalVue()
localVue.mixin(getTestMixin)

const wrapper = shallowMount(Test, {
    localVue,
})
Run Code Online (Sandbox Code Playgroud)

错误信息如下:

TypeError: Cannot read property 'props' of undefined
  46 | beforeEach(() => {
> 47 |  wrapper = shallowMount(Test, {
     |          ^
  48 |      localVue,
  49 |  });
  50 | });
Run Code Online (Sandbox Code Playgroud)

unit-testing vue.js

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

单元测试:如何在 React 中模拟 document.getElementById() ?

我想用玩笑测试以下代码。

有谁知道如何模拟document.getElementById()吗?

if (document.getElementById('estateList')) {
    render(
        <Provider store={store}>
            <EstateList />
        </Provider>,
        window.document.getElementById('estateList')
    );
}


if (document.getElementById('articleList')) {
    render(
        <Provider store={store}>
            <ArticleList />
        </Provider>,
        window.document.getElementById('articleList')
    );
}

if (document.getElementById('articleDetail')) {
    render(
        <Provider store={store}>
            <ArticleDetail />
        </Provider>,
        window.document.getElementById('articleDetail')
    );
}
Run Code Online (Sandbox Code Playgroud)

我想我可以将渲染放在函数中,例如:

function estateList() {
    render(
        <Provider store={store}>
            <EstateList />
        </Provider>,
        window.document.getElementById('estateList')

    );
}
Run Code Online (Sandbox Code Playgroud)

然后简单地测试estateList(),而不模拟document.getElementById(),但是有没有办法模拟document.getElementById()

javascript dom unit-testing reactjs jestjs

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

飞行前响应中的Access-Control-Allow-Headers不允许请求标头字段X-CSRF-TOKEN

我有一个laravel项目,当我运行php artisan serve时,浏览器显示错误:

Failed to load http://127.0.0.1:8000/api/news/get-news-list: Request header field X-CSRF-TOKEN is not allowed by Access-Control-Allow-Headers in preflight response.
Run Code Online (Sandbox Code Playgroud)

我的代码如下:

axios.get(domainName+'/api/news/get-news-list').then(response=>{
    news = response.data.list;
}).catch(function (error) {
    console.log(error);
});
Run Code Online (Sandbox Code Playgroud)

而且我已经添加了如下中间件:

内核.php

protected $middleware = [
    \App\Http\Middleware\Cors::class
];

protected $routeMiddleware = [
    'cors' => \App\Http\Middleware\Cors::class
];
Run Code Online (Sandbox Code Playgroud)

Cors.php

public function handle($request, Closure $next)
{
    return $next($request)
        ->header('Access-Control-Allow-Origin','*')
        ->header('Access-Control-Allow-Methods','GET,POST,PUT,PATCH,DELETE,OPTIONS')
        ->header('Access-Control-Allow-Headers','Content-Type,Authorization');

}
Run Code Online (Sandbox Code Playgroud)

api.php

Route::prefix('news')->group(function () {
    Route::get('get-news-list', 'API\NewsController@getList')->middleware('cors');
});
Run Code Online (Sandbox Code Playgroud)

谁能告诉我如何解决此问题?

cors laravel

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

如何在docker容器内使用php artisan serve?

我使用 dockerfile 创建了一个 php-composer 图像:

FROM php:7

RUN apt-get update 
RUN apt-get install curl
RUN curl -sS https://getcomposer.org/installer -o composer-setup.php
RUN php composer-setup.php --install-dir=/usr/local/bin --filename=composer
RUN apt-get install -y git
Run Code Online (Sandbox Code Playgroud)

我运行以下命令来创建一个容器并启动一个 Laravel 应用程序。

docker run -p 127.0.0.1:3000:8000 --name MyTest -dt php-composer to create a container
docker cp laravelApp/ d4bbb5d36312:/usr/
docker exec -it MyTest bash
cd usr/laravelApp
php artisan serve
Run Code Online (Sandbox Code Playgroud)

之后,容器的终端将显示成功信息:

Laravel development server started: <http://127.0.0.1:8000>
Run Code Online (Sandbox Code Playgroud)

但是当我在本地浏览器访问 127.0.0.1:3000 时,我什么也得不到。

那么是否有可能简单地运行 php artisan serve 来在 docker 容器内启动一个 Laravel 应用程序?

或者我必须使用 nginx 或 …

laravel docker

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

如何设置next.js?

我只是按照官方网站的步骤:

https://nextjs.org/docs/

第1步。

npm install --save next react react-dom
Run Code Online (Sandbox Code Playgroud)

步骤 2. 向 package.json 添加脚本

{
  "scripts": {
    "dev": "next",
    "build": "next build",
    "start": "next start"
  }
}
Run Code Online (Sandbox Code Playgroud)

步骤 3. 在项目中添加 ./pages/index.js:

export default () => <div>Welcome to next.js!</div>
Run Code Online (Sandbox Code Playgroud)

然后我运行 npm run dev 并得到错误:

/Users/jh/Documents/worksapce/react/nextJs/test1/node_modules/webpackbar/dist/index.js:55
    const hasRunning = () => Object.values(sharedState).find(s => s.isRunning);
                                ^

TypeError: Object.values is not a function
Run Code Online (Sandbox Code Playgroud)

我哪里做错了?

next.js

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

在 ubuntu 的哪里更改 php-fpm.conf 内的监听端口?

我想更改 php-fpm 监听的端口。

当我使用 osx 时,我可以简单地转到php-fpm.conf并更改:

listen = 127.0.0.1:9000
Run Code Online (Sandbox Code Playgroud)

listen = 127.0.0.1:9999
Run Code Online (Sandbox Code Playgroud)

现在我用的是ubuntu,在哪里可以更改端口?

php

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

laravel 5.5 jwt问题

当我尝试使用带有laravel"5.5"的jwt时出现问题(此问题仅发生在5.5版本上)

我正在学习本教程

当我试图在postMan上发帖时,我收到了这个错误

未找到"Tymon\JWTAuth\Providers\JWT\NamshiAdapter"类

错误信息

请帮助.

我把这个问题放在github上,这里是链接:


h ttps://github.com/jimmyHuey/jwt-test


php jwt laravel laravel-5.5

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