Taro学习-结合dva的使用 发表于 2019-10-21 更新于 2022-05-09 把Taro项目改造采用dva进行数据流管理 安装依赖script1npm i dva-core dva-loading --save 创建文件 utils/dva.js1234567891011121314151617181920212223242526import {create} from 'dva-core';import createLoading from 'dva-loading';let app;let store;let dispatch;function createApp(opt) { app = create(opt); app.use(createLoading({})); if (!global.registered) opt.models.forEach(model => app.model(model)); global.registered = true; app.start(); store = app._store; app.getStore = () => store; dispatch = store.dispatch; app.dispatch = dispatch; return app;}export default { createApp, getDispatch() { return app.dispatch; }} 创建models文件夹放你逻辑代码改造app.jsx1234567891011121314151617181920import {Provider} from '@tarojs/redux'import dva from './utils/dva'import models from './model/index'// dva 集成const dvaApp = dva.createApp({ initialState: {}, models: models,});const store = dvaApp.getStore();//包装render内容...render () { return ( <Provider store={store}> <Index /> </Provider> )}... 其它的操作就和 dva+react 差不多的了