dvajs / dva-knowledgemap Goto Github PK
View Code? Open in Web Editor NEWKnowledge map for dva.
Knowledge map for dva.
dva有没有cookie的解决方案?如何做到保持用户登录状态呢?
使用dva 2.0.1,router配置如下
import React from 'react';
import { Router, Switch, Route, IndexRoute } from 'dva/router';
import IndexPage from './routes/IndexPage'
import CountPage from './routes/CountPage'
function RouterConfig({ history }) {
return (
<Router history={history}>
<Route path="/" component={IndexPage}>
{/*<Switch>*/}
<Route path="/count" component={CountPage}/>
<Route path="/statements" component={CountPage}/>
{/*</Switch>*/}
</Route>
</Router>
);
}
export default RouterConfig;
在IndexPage中输出的props里面没有children和routes
import React from 'react';
import { connect } from 'dva';
import styles from './IndexPage.css';
import { Layout } from 'antd'
import Header from '../components/Header'
const { Sider, Content, Footer } = Layout;
const IndexPage = (props) => {
const { children, routes } = props;
console.log(props);
return (
<Layout>
<Header routes={routes}>header</Header>
<Layout>
<Sider>sider</Sider>
<Content>{children || "No content"}</Content>
</Layout>
<Footer>2017</Footer>
</Layout>
);
}
* getUserInfo({payload}, {call, put}) {
let response = yield call(getUserInfo);
if (response && !response.code) {
yield put({
type: 'save',
payload: {
userInfo: response.model
}
});
}
},
@sorrycc 我在subscriptions中dispatch引发redux-soga浏览器抛异常:uncaught at sagaWithCatch
下面是demo中的代码:
namespace : 'user',
state : {
currentUser : {}
},
subscriptions : {
setup({ dispatch, history }) {
history.listen(location => {
dispatch({
type: 'check',
});
});
},
},
effects : {
*check({ }, { select, call, put }) {
try {
const currentUser = yield select(({ user }) => user.currentUser);
if (window.$.isEmptyObject(currentUser)) {
yield put(routerRedux.push('/login'));
}
} catch (err) {
console.log(err);
}
},
浏览器console报错uncaught at sagaWithCatch,并且错误指向了下面的代码((anonymous function) @ user.js:30):
history.listen(function (location) {
dispatch({
type: 'check'
});
});
请教一下问题可能出在哪里?3Q
How to setup the subscriptions
' Data Source with any particular time
, where I will get the time from the effects
or reducers
?
在教程里,提到基于action的跳转的时候,有如下例子。
// Outside Effects
dispatch(routerRedux.push('/logout'));
// With query
routerRedux.push({
pathname: '/logout',
query: {
page: 2,
},
});
为什么带参数的跳转,不需要dispatch了呢?
感到迷茫,还请解惑。
版本
"dva": "^1.2.1",
"history": "^4.6.1",
"react": "^15.4.0",
import dva from 'dva';
import { createHashHistory } from 'history';
import { browserHistory, hashHistory, useRouterHistory } from 'dva/router';
import createLoading from 'dva-loading';
const app = dva({
...createLoading(),
history: useRouterHistory(createHashHistory)({ queryKey: false }),
onError (error) {
console.error('app onError -- ', error);
}
});
// 2. Plugins
// app.use({});
// 3. Model
app.model(require('./models/app'));
// app.model(require("./models/main"));
// 4. Router
app.router(require('./router'));
// 5. Start
app.start('#root');
import React, { PropTypes } from 'react';
import { Router, Route, browserHistory } from 'dva/router';
import App from './routes/app/';
function Routers ({ history, app }) {
const routes = [{
path: '/',
component: App,
getIndexRoute (nextState, cb) {
require.ensure([], require => {
cb(null, { components: require('./routes/main/') });
}, 'main');
},
childRoutes: [
{
path: '/console',
getComponent (nextState, cb) {
require.ensure([], require => {
cb(null, require('./routes/console/'));
}, 'console');
}
},
{
path: '*',
getComponent (nextState, cb) {
require.ensure([], require => {
cb(null, require('./routes/error/'));
}, 'error');
}
}
]
}];
return (<Router history={history} routes={routes} />);
}
Routers.propTypes = {
history: PropTypes.object,
app: PropTypes.object
};
export default Routers;
设置 history: browserHistory 无效
默认导出一部分那个extend不应该是extends吗?
请问effect能够调用其他的effect吗?我尝试用put方法没有用。
另外,我想请问一下,effect要怎么通知到界面中去呢?
比如我登录成功,想在界面返回一个“登录成功”的消息弹窗,需要怎么实现?
谢谢。
启动项目的步奏,里面少了npm intsall,然后再npm start
dva 与 apollo 相似?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.