import yfieldsControls from "../yfieldsControls" Component({ behaviors:[yfieldsControls], properties: { bindValue: String, defaultValue: String, placeholder: { type: String, value: "请输入", }, }, relations: { '../yform/yform': { type: 'ancestor', // 关联的目标节点应为祖先节点 linked: function(target){ this.updateFormItemValue = (curValue) =>{ target.data.form[this.data.bindValue] = curValue } } } }, lifetimes: { attached: function () { this.dataset[this.data.bindValue] = this.data.defaultValue ?? '' } }, methods: { // 这个方法是父组件提供的,这里只是为了不报错 updateFormItemValue: (data:string) => {}, bindinput: function (event: WechatMiniprogram.Input) { this.dataset[this.data.bindValue] = event.detail.value this.updateFormItemValue(event.detail.value) } } })