支付宝小程序ref 获取组件实例(页面获取组件中的方法)

149 阅读1分钟

inputbox中的方法

controlinputhd: function (e) {
      if (e == "wxchat") {
        this.setData({
          "morelist[0].hidden": false,
          "morelist[1].hidden": false,
          "morelist[2].hidden": false,
          "morelist[3].hidden": false,
        })
      } else if (e == "dychat") {
        this.setData({
          "morelist[0].hidden": false,
          "morelist[1].hidden": false,
          "morelist[2].hidden": true,
          "morelist[3].hidden": false,
        })
      } else if (e == "bdchat") {
        console.log("bdchat")
      }
      else if (e == "zfbchat") {
        console.log("inputbox zfbchat")
      }
    },

navbar中的方法

controlhd: function (e) {
      if (e == "wxchat") {
        this.setData({
          hdseecard: false,
          hdaddwx: false,
          hdcalltel: false,
          hdbackcall: false,
          hdbackto: false,
        })
      } else if (e == "dychat") {
        this.setData({
          hdseecard: false,
          hdaddwx: false,
          hdcalltel: false,
          hdbackcall: false,
          hdbackto: false,
        })
      } else if (e == "zfbchat") {
        console.log("navbar zfbchat")
      }
    }

<inputbox ref="saveRef" ></inputbox>
<navbar ref="navbar" ></navbar>
<view onTap="open" ></view>
onReady: function (e) {
    this.counter.controlinputhd("zfbchat");
    this.navbar.controlhd("zfbchat")
  },

open() {
    this.counter.closeadd();
    this.counter.openFaces();
  },
  saveRef(ref) {
    this.counter = ref;
  },
  navbar(ref) {
    this.navbar = ref
  },