微信小程序之全局狀態管理


本文記錄微信小程序做到vuex的全局狀態管理管理功能:

js庫請去下方GitHub地址下載;

實例store:

import Store from './store.js'

export default new Store({
  // 全局狀態初始值
  state: {
    msg: '這是一個全局狀態',
    registerFormData : {},
    findPwdFirstCode: ``,
    findPwdSecondCode: ``
  },
  openPart: true
})

app.js引入掛載:

// 全局狀態管理
import store from './store/index'

App({
    store,
    onLaunch:function(){}
})

頁面用法:

// 頁面js文件
Page({
    useStore: true,
    data: {}
})

// 更改狀態
App.store.setState({
    msg: '我改變了'
})

// 獲取狀態
this.data.$state.msg

// wxml引用
<view>{{$state.msg}}</view>

 

GitHub:https://github.com/yx675258207/wxMiniStore

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM