微信小程序:简易数据双向绑定

423 阅读1分钟

文档:

简易双向绑定

<input model:value="{{value}}" />

注意:只能绑定一个单一字段

自定义双向绑定

// custom-component.js
Component({
  properties: {
    myValue: String
  },

  methods: {
    update: function() {
      // 更新 myValue
      this.setData({
        myValue: 'leaf'
      })
    }
  }
})

使用组件

<custom-component model:my-value="{{pageValue}}" />