小编Roh*_*Rad的帖子

如何从react.js中的父级调用功能组件中子级的功能?

我有两个组成部分:

  1. 父母
  2. 孩子

父组件是类组件,子组件是功能组件。从父组件调用子方法的最佳实践是什么?

这些组件的目标是能够动态加载 svg 文件。

父组件:

class UnitMonitor extends PureComponent {
  constructor() {
    super();
  }
  state = {
    img: null,
  };
  onChangeShcema = schemaID => {
    axios.get("/api/schemata/get-schemata-nodes/" + schemaID).then(response => {
      let path = response.data["0"]["file"];
      // call loadFile function of child component is needed
    });
render() {
    return (
      <Row type="flex" className="">
        <Col span={25}>
          <SvgViewer />
        </Col>
      </Row>
    );
  }
  };
Run Code Online (Sandbox Code Playgroud)

子组件:

const SvgViewer = () => {

  const loadFile = path => { 
    let svgFile = require("./images/" …
Run Code Online (Sandbox Code Playgroud)

reactjs

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

Laravel 5.3:如何在全局中间件中使用检查身份验证?

我想在我的网站的标题和其他一些视图中显示未读邮件的数量。为此,我编写了一个全局中间件,但该中间件无法访问已注册用户的身份验证信息。

<?php

namespace PTA_OIMS\Http\Middleware;

use Illuminate\View\Factory;
use Closure;
use Illuminate\Contracts\Auth\Guard;
use PTA_OIMS\Kartable;
use Session;

class UnreadMessage
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */

    protected $auth;
    protected $view;

    public function __construct(Guard $auth, Factory $view)
    {
        $this->auth = $auth;
        $this->view = $view;
    }

    public function handle($request, Closure $next)
    {
        $unreadMessage = NULL;
        $user = $this->auth->check();
        if (!empty($user)) {
            $unreadMessage = Kartable::
            where('id_reciver', '=',
                Session::get('personnel_info.0')->box_id)
                ->whereBetween('status', [1, 2])
                ->where('view_date', '=', …
Run Code Online (Sandbox Code Playgroud)

authentication middleware laravel

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

如何在Laravel5中禁用所有路由的CSRF保护

在没有使用VerifyCsrfToken middelware和$ except []数组的情况下,Laravel 5.2中是否有任何方法可以禁用所有路由的csrf保护?

protection csrf laravel laravel-5.2

3
推荐指数
2
解决办法
2779
查看次数