Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

自定义表单组件如何设置默认值? #1141

Closed
11003 opened this issue Apr 7, 2024 · 5 comments
Closed

自定义表单组件如何设置默认值? #1141

11003 opened this issue Apr 7, 2024 · 5 comments

Comments

@11003
Copy link

11003 commented Apr 7, 2024

ae3f976dcdcc54731c9480e9c917fa51

@11003
Copy link
Author

11003 commented Apr 7, 2024

  this.form.setFieldValue('like', ['basketball','badminton'])

@11003 11003 closed this as completed Apr 7, 2024
@rayhomie
Copy link
Collaborator

rayhomie commented Apr 7, 2024

需要在Form实例化之后再去调用setFieldValue方法,onLoad中的话setTimeout试试

@11003 11003 reopened this Apr 7, 2024
@11003
Copy link
Author

11003 commented Apr 7, 2024

需要在Form实例化之后再去调用setFieldValue方法,onLoad中的话setTimeout试试

我组件里面的formData.value有值了,如何把formData.value正确赋值给图片列表imageList呢?
image

@11003
Copy link
Author

11003 commented Apr 7, 2024

修改了处理方法:

didMount() {
		nextTick(() => {
			let data = this.getFormData()
			if (data.value) {
				this.setData({
					imageList: typeof data.value === 'string' ? [data.value] : data.value,
					statusArr: ['1']
				})
			}
		}, 300)
	},

@rayhomie
Copy link
Collaborator

rayhomie commented Apr 7, 2024

array.push直接修改了小程序的data,不建议这样做。可以换成[...statusArr, '1']

@rayhomie rayhomie closed this as completed Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants