syzyn

  

在 WXML 中,普通的属性的绑定是单向的。例如:

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

如果需要在用户输入的同时改变 this.data.value ,需要借助简易双向绑定机制。此时,可以在对应项目之前加入 model: 前缀:

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

用于双向绑定的表达式有如下限制:

1.只能是一个单一字段的绑定,如

<input model:value="值为 {{value}}" />
<input model:value="{{ a + b }}" />

2.不能 data 路径

<input model:value="{{ a.b }}" />

 

组件中也支持简易绑定

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

<!-- custom-component.wxml -->
<input model:value="{{myValue}}" />

使用组件
<custom-component model:my-value="{{pageValue}}" />

详情见: https://developers.weixin.qq.com/miniprogram/dev/framework/view/two-way-bindings.html 

 

分类:

技术点:

相关文章:

  • 2021-07-17
  • 2021-12-29
  • 2021-10-29
  • 2022-02-11
  • 2021-12-14
  • 2021-10-26
  • 2021-08-17
  • 2021-11-11
猜你喜欢
  • 2022-01-23
  • 2021-11-29
  • 2021-10-12
  • 2021-07-30
  • 2021-06-29
  • 2021-06-18
相关资源
相似解决方案