美文网首页
小程序radish_wx_mini_store包

小程序radish_wx_mini_store包

作者: RadishHuang | 来源:发表于2020-07-13 11:00 被阅读0次
    • yarn add radish_wx_mini_store
    • 初始化,在app.js里面初始化需要的方法
    
    
    const wx_mini_store = require('radish_wx_mini_store');
    const aldstat = require('./utils/ald-stat/ald-stat');
    
    App({
      store: wx_mini_store.store,
      create: wx_mini_store.create,
      regeneratorRuntime: wx_mini_store.regeneratorRuntime,
      aldstat,
      onLaunch() {
        // 初始化项目
        const params = {
          default: require('./utils/config/default'),
          develop: require('./utils/config/develop'),
          trial: require('./utils/config/trial'),
          prod: require('./utils/config/prod'),
        }
        
        wx_mini_store.init(params);
      },
    
      // 其他小程序跳转回来有传递参数只在这里触发
      onShow(options) { 
        try {
          const extraData = options.referrerInfo.extraData;
        } catch (error) {
          console.log(' onshow error ', error);
        }
      }
    })
    
    • 页面中使用
    //  小程序主入口 授权 中转页面
    
    const store = getApp().store;
    const create = getApp().create;
    const regeneratorRuntime = getApp().regeneratorRuntime;
    
    
    
    create(store, {
        data: {
            focus: false
        },
        onLoad() {
            
    
            this.store.watch(this.watch());
    
            this.store.data.userInfo = {
                name: 'radish',
                age: 10
            };
    
        },
        changeValue() {
            this.store.data.userInfo.name = 'kkk';
            this.update();
        },
    
        watch() {
            return {
                'userInfo': (value) => {
                    console.log('userInfo 数据发生改变', value);
                }
            }
        },
    });
    
    
    
    
    
    
    

    相关文章

      网友评论

          本文标题:小程序radish_wx_mini_store包

          本文链接:https://www.haomeiwen.com/subject/revmcktx.html