超碰中文网,91久久精品日日躁夜夜躁欧美,一区二区三区精品道,一区二区国产在线观看,亚洲精品中文字幕乱码一区二区,天天看片高清影视在线观看,久久99精品久久久久蜜桃,久久成人影视

VPS參考測評推薦
專注分享VPS主機優惠信息
衡天云優惠活動
熱網互聯2026年促銷活動
hostkvm優惠促銷活動
zji優惠促銷活動
QQGNET優惠促銷活動
QQGNET優惠促銷活動

使用wepy-redux并在小程序中保存全局變量(微信小程序中如何定義全局變量)

主機參考:VPS測評參考推薦/專注分享VPS服務器優惠信息!若您是商家可以在本站進行投稿,查看詳情!此外我們還提供軟文收錄、PayPal代付、廣告贊助等服務,查看詳情!
我們發布的部分優惠活動文章可能存在時效性,購買時建議在本站搜索商家名稱可查看相關文章充分了解該商家!若非中文頁面可使用Edge瀏覽器同步翻譯!PayPal代付/收錄合作

Wepy推薦使用wepy-redux來存儲全局變量。

使用方法 1.初始化store // app.wpyimport { setStore } from 'wepy-redux'import configStore from './store' const store = configStore()setStore(store) // setStore為Insert store 導入頁面 // store 文件夾下的index.jsimport { createStore, applyMiddleware } from 'redux'import PromiseMiddleware from 'redux-promise'import rootReducer from ' ./reducers'export default function configStore () { const store = createStore(rootReducer, applyMiddleware(promiseMiddleware)) //創建store對象 return store}

applyMiddleware函數的功能是擴展和增強store.dispatch方法。 這里的改造是使用 redux-promise 解決異步問題

Get storeimport { getStore } from 'wepy-redux' const store = getStore()//dispatchstore.dispatch ({type: 'xx ', payload: data}) //xx 是reducer 名稱,payload 是正在傳輸的數據。 store.dispatch(getAllHoomInfo(store.getState().base))) //xx 是操作名稱。 //獲取stateconst state = store.getState()3. 連接組件 @connect({ data:(state) => state.base.data //這里注意下面的base是state,添加base }) 文件引入 redux file

type

types 觸發操作的函數的名稱。 只存儲函數名

根據模塊創建type.js

//base.jsexport const GETALLHOMEINFO = 'GETALLHOMEINFO'

函數名寫入

export * from './counter'export * from ' ./base'reducers

隨著您的應用程序變得更加復雜,您可能需要拆分reducer 函數。 每個劃分的部分獨立管理其狀態的一部分。 此時多個模塊的reducer會被combineReducers合并成最終的reducer。 函數,

import {combinReducers } from 'redux'importbase from './base'import counter from './counter'exportdefaultcombinReducers({base, counter})

這個模塊使用handleActions處理reducer,并將多個相關的reducer寫在一起。 handleActions 有兩個參數。 第一個是多個減速器,第二個是初始狀態。

GETALLHOMEINFO 減速器返回異步操作。 該值被分配給數據。

//base.js導入{ handleActions } from 'redux-actions'import { GETALLHOMEINFO } from '../types/base'constInitialState = { data: {}}導出默認的handleActions({ [GETALLHOMEINFO] (state, action) { return { . . .state, data: action.payload } }}, initialState)actions

Actions 正在處理數據

在index.js 中導出

export * from './counter ' export * from './base'

createAction 用于創建操作

import { GETALLHOMEINFO } from '../types/base'import { createAction } from 'redux-actions'import { Http , Apis } from '../../libs/interface'export const getAllHoomInfo = createAction(GETALLHOMEINFO, (base) => { return new Promise(asyncsolve => { let data = wait Http.get({ url: Apis . ls_url + Apis. allHomeInfo, data: {} })solve(data)** //返回Reducer中的action.payload })}) 用法 <script> import wepy from 'wepy' import { connect } from 'wepy-redux' import { getAllHoomInfo } from '../store/actions/base.js' //引入action方法 import { getStore } from ' wepy-redux' const store = getStore() @connect({ data:(state) => state.base.data }) 導出默認類 Index 擴展 wepy .page { data = { } 計算 = { } onLoad() { store.dispatch(getAllHoomInfo(store.getState().base)) } }

推薦教程:《微信小程序》

PHP 快速學習視頻免費教程(入門到精通)

如何學習PHP?如何快速學習PHP? 任何想要的朋友(從初級到高級)都可以保存并下載來學習。下載

這幾篇文章你可能也喜歡:

本文由主機參考刊發,轉載請注明:使用wepy-redux并在小程序中保存全局變量(微信小程序中如何定義全局變量) http://m.k2270.com/123755.html

【騰訊云】領8888元采購禮包,搶爆款云服務器 每月 9元起,個人開發者加享折上折!
打賞
轉載請注明原文鏈接:主機參考 » 使用wepy-redux并在小程序中保存全局變量(微信小程序中如何定義全局變量)
主機參考僅做資料收集,不對商家任何信息及交易做信用擔保,購買前請注意風險,有交易糾紛請自行解決!請查閱:特別聲明

評論 搶沙發

評論前必須登錄!