Skip to content

Commit

Permalink
8. User dva-loading to handle loading state
Browse files Browse the repository at this point in the history
  • Loading branch information
sorrycc committed Dec 19, 2016
1 parent 94788e5 commit e256165
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 19 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"antd": "^2.5.2",
"babel-runtime": "^6.9.2",
"dva": "^1.1.0",
"dva-loading": "^0.2.0",
"react": "^15.4.0",
"react-dom": "^15.4.0"
},
Expand Down
14 changes: 0 additions & 14 deletions src/components/Example.js

This file was deleted.

4 changes: 3 additions & 1 deletion src/components/Users/Users.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Table, Pagination, Popconfirm } from 'antd';
import styles from './Users.css';
import { PAGE_SIZE } from '../../constants';

function Users({ list: dataSource, total, page: current }) {
function Users({ list: dataSource, loading, total, page: current }) {
function deleteHandler(id) {
console.warn(`TODO: ${id}`);
}
Expand Down Expand Up @@ -46,6 +46,7 @@ function Users({ list: dataSource, total, page: current }) {
<Table
columns={columns}
dataSource={dataSource}
loading={loading}
rowKey={record => record.id}
pagination={false}
/>
Expand All @@ -63,6 +64,7 @@ function Users({ list: dataSource, total, page: current }) {
function mapStateToProps(state) {
const { list, total, page } = state.users;
return {
loading: state.loading.models.users,
list,
total,
page,
Expand Down
7 changes: 3 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import dva from 'dva';
import createLoading from 'dva-loading';
import './index.html';
import './index.css';

// 1. Initialize
const app = dva();

app.model(require("./models/users"));

// 2. Plugins
// app.use({});
app.use(createLoading());

// 3. Model
// app.model(require('./models/example'));
app.model(require('./models/users'));

// 4. Router
app.router(require('./router'));
Expand Down

13 comments on commit e256165

@lichenchen123
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

三三四四

@lichenchen123
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

111

@blackdevila
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/index.js中 import './index.html'是什么鬼? 另外代码完全复制之后没有loading效果 看着代码都一样 就插件版本号不同 是那的关系吗?

@bestsamcn
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感觉这样相当麻烦啊,如果统一在ajax封装的方法里面处理loading,那多优雅,为啥要这么搞呢,每个组件都要一个spin组件,感觉代码冗余了啊

@sorrycc
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dva 的数据和组件是分离的,统一封装在 ajax 里的有具体方案呢?

@YiBanCangBai
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

一路考代码,突然发现,src目录下没有index.html,而是index.ejs

@Hsinky
Copy link

@Hsinky Hsinky commented on e256165 Sep 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sorrycc 您好,state.loading.models下面没有我自定义的对象,怎么处理?
qq 20170927164453

@zhangyang110
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有问题吧???这一段

@showkiwi
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

index.html

<title>Dva Demo</title>
<script src="index.js"></script>

@showkiwi
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Dva Demo</title>
  <link rel="stylesheet" href="index.css" />
</head>
<body>

<div id="root"></div>

<script src="index.js"></script>

</body>
</html>

@alfredli2017
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Hsinky 首字母你大写了

@lettywiterock
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

无状态组建怎么把loading传进去啊!
找不到传递位置。

@lettywiterock
Copy link

@lettywiterock lettywiterock commented on e256165 Apr 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

route页面使用了connect(({ loading})加载到了loading,
问题解决了,无状态都是用connect加载的

Please sign in to comment.