There is a requirement that you have a form in which you want to upload an image. I want to sign UI, so I wrote a component that uploads images. The image is mandatory. If the image is triggered first and then uploaded, the red mandatory prompt will not disappear.

1

First of all, simply, I thought ElForm bound to data, and ElFormItem bound to properties, so maybe ElFormItem directly watches properties. The image property is then explicitly written into the Data Form object. Well, it’s no use.

So I remember ElFormItem source code to monitor the change event, to making = > element – UI = > v2.15.7 = > element directory/packages/form/SRC/form – item. Vue

Indeed as expected.

2

Can I just trigger it? I remember the vue $emit is triggered within components, unable to cross level, to making = > vue = > v2.6.14 = > directory vue/SRC/core/instance/events. Js

Sure enough, event is stored in instance _events

3

If there is a listener, there must be a trigger, and remember that the trigger is clearly written in Element2. Look for a form component: the ELInput component

4

I used dispatch. Where’d you get that? I remember seeing a mixin folder before, it must be the mixin folder, and will not directly global mixin, that must be the mixin component. Indeed as expected.

Is indeed the element/SRC/mixins/emitter. The js files in a mixin

5

Here’s the question: Can I use it? Or is this file locally available? Take a look at the Element-UI package

The package.json file files field contains the SRC folder, indicating that NPM install will directly download the SRC file during installation, which must contain the mixin file. So start using it.

6

Imitate ElInput:

import emitter from 'element-ui/src/mixins/emitter'

export default {
	mixins: [emitter],
        ...
        
            this.dispatch('ElFormItem'.'el.form.change', [value])
            ...
Copy the code

Trigger el.form.change when the image is set

Finally, look at the dispatch method, which keeps looking up to find the trigger.

OVER.