1.安裝taro開發(fā)工具
//npm
npm install -g @tarojs/cli
//yarn
yarn global add @tarojs/cli
2.創(chuàng)建項目
taro init taroApp
3.引入dva
npm i dva-core dva-loading --save
4.在src 下新建目錄 utils ,目錄下新建文件dva.js
import { create } from 'dva-core';
import { createLogger } from 'redux-logger';
import createLoading from 'dva-loading';
let app;
let store;
let dispatch;
function createApp(opt) {
// redux日志
// opt.onAction = [createLogger()];
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;
}
}
//此時運(yùn)行項目若出錯找不到nervjs;
npm install 安裝 nervjs
5.在項目入口aap.js引入
//先引入models,在src 下新建models目錄,在目錄下新建index.js文件,整合pages的models
import models from './models'
import dva from './utils/dva'
const dvaApp = dva.createApp({
initialState: {},
models: models,
});
const store = dvaApp.getStore();
6.安裝taro-ui
npm install taro-ui
7.使用 taro-ui
// page.js
import { AtButton } from 'taro-ui'
// 除了引入所需的組件冀痕,還需要手動引入組件樣式
// app.js
import 'taro-ui/dist/style/index.scss' // 全局引入一次即可
8.然后即可進(jìn)行頁面的開發(fā)