假设vue里有个form表单对象:
form: { id: null, projectName: null, state: '100', typeId: null, typeName: null }
当typeId变化时,实时修改typeName的值(因为是回调修改,其实有点延时)
使用watch监听typeId
watch: { 'form.typeId': { handler: function() { if (!this.form.typeId) { this.form.typeName = null return } this.form.typeName = this.projectTypeOptions.find(item => { return item.key === this.form.typeId }).display_name } } }