当前位置: 首页 > wzjs >正文

湖北省网站建设wordpress 人物页面

湖北省网站建设,wordpress 人物页面,58同城济南网站建设,广州平台网站建设两个框架扩展提供的 ComponentWithStore 与 ComponentWithComputed 方法无法结合使用。如果需要在一个组件中既想使用 mobx-miniprogram-bindings 又想使用 miniprogram-computed解决方案是: 使用旧版 API 自定义组件仍然使用 Component 方法构建组件,将…
  • 两个框架扩展提供的 ComponentWithStoreComponentWithComputed 方法无法结合使用。
  • 如果需要在一个组件中既想使用 mobx-miniprogram-bindings 又想使用 miniprogram-computed解决方案是:
    1. 使用旧版 API

      • 自定义组件仍然使用 Component 方法构建组件,将两个扩展依赖包的使用全部改为旧版 API
      • mobx-miniprogram-bindings 官方文档
      • miniprogram-computed 官方文档
    2. 使用兼容写法

      • 即要么使用 ComponentWithStore 方法构建组件,要么使用 ComponentWithComputed 方法构建组件

      • 如果使用了 ComponentWithStore 方法构建组件,计算属性写法使用旧版 API

      • 如果使用了 ComponentWithComputed 方法构建组件,Mobx写法使用旧版 API

一、安装 miniprogram-computed 和 mobx-miniprogram

  1. 在项目的根目录下,使用如下命令,将快速在根目录下初始化生成一个 package.json 文件
    npm init -y
    
  2. 安装 miniprogram-computed 和 mobx-miniprogram
    npm install miniprogram-computed 
    
    npm install mobx-miniprogram mobx-miniprogram-bindings
    
  3. 然后 在 微信开发者工具 的左上角 点击 》工具》 构建 npm,构建成功后,将会在项目根目录下生成 miniprogram_npm 文件夹,可以在 miniprogram_npm 文件夹中看见构建的结果

二、在 ComponentWithStore 构建的组件中使用 计算属性

  1. 在项目的根目录下的 components 文件夹中(没有该文件夹的需要自己创建)新建 custom04 文件夹,并在该文件夹中创建 custom04组件(在文件夹上点击鼠标右键,选择 新建 component

  2. 找到项目根目录下的 app.json 文件,增加如下代码,将 custom04组件注册为 全局组件

    {// ...其他配置项"usingComponents": {"custom04": "./components/custom04/custom04"}
    }
    
  3. pages/index.wxml 中使用 custom04 组件

    <custom04 />
    
  4. 修改components/custom04/custom04.js 文件, Component 方法替换成 ComponentWithStore 方法

    // components/custom04/custom04.js
    import {ComponentWithStore
    } from 'mobx-miniprogram-bindings'// 导入计算属性 behavior
    const computedBehavior = require('miniprogram-computed').behaviorComponentWithStore({// storeBindings 不再复述// 注册 behaviorbehaviors: [computedBehavior],data: {a: 1,b: 2},computed: {total(data) {console.log('q23');return data.a + data.b}},watch: {'a,b': function (a, b) {console.log(`a更新之后的数据:` + a);console.log(`b更新之后的数据:` + b);}},methods: {updateData() {this.setData({a: this.data.a + 1,b: this.data.b + 1})}}})
    
  5. 修改components/custom04/custom04.wxml 文件

    <view>{{a}} + {{b}} = {{total}}</view>
    <button type="warn" bind:tap="updateData">修改数据</button>
    

三、在 ComponentWithComputed 构建的组件中使用 状态管理

  1. 在项目的根目录下创建 stores 文件夹,然后在该文件夹下新建 numStore.js 文件

  2. /stores/numStore.js 导入 observable action 方法。使用 observable 方法需要接受一个 store 对象,存储应用的状态

    import {observable,action
    } from 'mobx-miniprogram'export const numStore = observable({numA: 1,numB: 2,// 使用 action 更新 numA 以及 numBupdate: action(function () {this.numA += 1this.numB += 1}),// 计算属性,使用 get 修饰符,get sum() {return this.numA + this.numB;}
    })
    
  3. 在项目的根目录下的 components 文件夹中(没有该文件夹的需要自己创建)新建 custom05 文件夹,并在该文件夹中创建 custom05组件(在文件夹上点击鼠标右键,选择 新建 component

  4. 找到项目根目录下的 app.json 文件,增加如下代码,将 custom05 组件注册为 全局组件

    {// ...其他配置项"usingComponents": {"custom05": "./components/custom05/custom05"}
    }
    
  5. pages/index.wxml 中使用 custom05 组件

    <custom05 />
    
  6. 修改components/custom05/custom05.js 文件, Component 方法替换成 ComponentWithComputed 方法

    // components/custom05/custom05.js
    import {ComponentWithComputed
    } from 'miniprogram-computed'import {storeBindingsBehavior
    } from 'mobx-miniprogram-bindings'import {numStore
    } from '../../stores/numStore'ComponentWithComputed({behaviors: [storeBindingsBehavior],storeBindings: {store: numStore,fields: ['numA', 'numB', 'sum'],actions: ['update']}
    })
    
  7. 修改components/custom05/custom05.wxml 文件

    <!--components/custom05/custom05.wxml-->
    <view>{{numA}} + {{numB}} = {{sum}}</view>
    <button type="primary" bind:tap="update">更新store 中的数据</button>
    

文章转载自:

http://ehYKCkWq.LmLft.cn
http://sFI0fmO7.LmLft.cn
http://bytaJc8C.LmLft.cn
http://h8biHZll.LmLft.cn
http://4FOVcxlA.LmLft.cn
http://fbnasA5U.LmLft.cn
http://LytJf5a8.LmLft.cn
http://OaXoHByH.LmLft.cn
http://FlyTNHUO.LmLft.cn
http://xm5KBlfb.LmLft.cn
http://eiw0iP0F.LmLft.cn
http://qx2xdxG6.LmLft.cn
http://RLWmNwma.LmLft.cn
http://sGZRu13d.LmLft.cn
http://Qxae2Vhv.LmLft.cn
http://e1L5Opiq.LmLft.cn
http://Mnqdc4pY.LmLft.cn
http://3KmmHlc5.LmLft.cn
http://MIbYB735.LmLft.cn
http://sDg4jCPp.LmLft.cn
http://7FGA3aPn.LmLft.cn
http://AKIHOoPW.LmLft.cn
http://fMJky6oO.LmLft.cn
http://mbpIiOEj.LmLft.cn
http://TVYEMjQ1.LmLft.cn
http://dccDGjsa.LmLft.cn
http://eT59SEgM.LmLft.cn
http://11GCVq00.LmLft.cn
http://BoVMiqsZ.LmLft.cn
http://DFiJkcbi.LmLft.cn
http://www.dtcms.com/wzjs/621098.html

相关文章:

  • 做网站做软件怎么赚钱吗中国电子商务官网
  • 怎么在国外的搜索网站做推广网站搭建技术
  • 一个ip做网站阿里云nas做网站
  • 山东做网站建设的好公司排名wordpress active
  • 太原制作微信网站电商产品营销推广
  • 自己的网站怎么做砍价公司网站建设改版
  • 网站平台建设服务合同企业管理软件定制开发
  • 如何查网站处罚过凡科建站登录界面
  • 做捕鱼网站电话女教师遭网课入侵直播
  • 乌海建设网站wordpress快速清除本地图片
  • 网站模板模仿南宁住房建设部网站
  • 营销型网站的特点网站编辑是个长期做的工作吗
  • 做网站时搜索的代码是什么商城网站程序
  • 电脑网站和手机网站怎么做相同路径北京 网站设计找时代创信好
  • 个人主页怎么找滁州百度seo
  • 济南模版网站秦皇岛黄金海岸门票多少钱
  • wordpress页面添加分类目录长沙seo网站优化
  • 石家庄网站开发设计网站怎么收录
  • 云南网站建设产品介绍那个网站推作者
  • 怎么选择一家好的网站建设公司苏州网站排名
  • 怎么才能让网站图文展示网站单页面怎么做
  • 阎良网站建设30天网站建设实录光盘云盘
  • 188旅游网站管理系统6.0模板益阳市 网站建设
  • 域名可以绑定几个网站网站图片如何做超链接
  • 无需代码制作app软件北京seo运营推广
  • 网站建设工作室 怎么样用网站做淘客怎么赚钱
  • 上海做网站大的公司建设行政主管部门政务网站
  • 揭阳seo网站管理mysql 网站空间
  • 网站建设卖花网站的目的网络营销心得体会300字
  • 做建站较好的网站多语言 网站