Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

为什么src/pages/components/RegisterAreaSelect/model.js无法使用 #2464

Closed
curry-wxj opened this issue May 23, 2019 · 7 comments
Closed

Comments

@curry-wxj
Copy link

我在 创建了 这个文件 src/pages/components/RegisterAreaSelect/model.js
在 src/pages/components/RegisterAreaSelect/index.js 使用不了

@sorrycc
Copy link
Member

sorrycc commented May 24, 2019

给最小可复现例子。

@curry-wxj
Copy link
Author

curry-wxj commented May 24, 2019

src/pages/components/RegisterAreaSelect/model.js
内容

export default {
  namespace: 'registerAreaSelect',
  state: {
    areaData: 123, // 注册区域数据
    parkData: 456, // 注册园区数据
  },
  effects: {
    *query({ payload }, { call, put }) {},
  },
  reducers: {
    loadData(state, { payload }) {
      return {
        ...state,
        ...payload,
      }
    },
  },
}

src/pages/components/RegisterAreaSelect/index.js
内容

import React from 'react'
import { connect } from 'dva'

@connect(({ registerAreaSelect, loading }) => ({
  areaData: registerAreaSelect.areaData,
}))
class RegisterAreaSelect extends React.PureComponent {

  render() {
     const { areaData } = this.props
     return <div>{areaData}</div>
  }
}

export default RegisterAreaSelect

报错信息
image
@sorrycc

@freedom520
Copy link

我也遇到类似的问题了,求解~

@sorrycc
Copy link
Member

sorrycc commented May 26, 2019

给最小可复现仓库。

@superchow
Copy link

superchow commented May 26, 2019

应该是整个 components 文件夹被排除了,没作为页面时;pages文件夹下的model会在进入页面时注册models
image

试试在connect 前手动注册model (未试过)

window.g_app.model({ namespace: 'registerAreaSelect', ...(require('src/pages/components/RegisterAreaSelect/model.js').default) });

require 应该换成 import,所以应该是这样的

import model form '@/components/RegisterAreaSelect/model.js';
window.g_app.model({ namespace: 'registerAreaSelect', ...model  });

@sorrycc
Copy link
Member

sorrycc commented May 26, 2019

@superchow +1

@curry-wxj
Copy link
Author

已解决
是因为 配置了 routes.exclude 路由过滤掉了 components 所以在 components 中不能使用model.js

'umi-plugin-react',
      {
        dva: { immer: true },
        antd: true,
        'antd-pro': true,
        routes: {
          exclude: [
            /model\.(j|t)sx?$/,
            /service\.(j|t)sx?$/,
            /models\//,
            /components\//,
            /services\//,
          ],
        },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants