目录
1.emitter.JS
function broadcast (componentName, eventName, params) {this.$children.forEach(child => {var name = child.$options.componentNameif (name === componentName) {child.$emit.apply(child, [eventName].concat(params))} else {broadcast.apply(child, [componentName, eventName].concat([params]))}})
}export default {methods: {dispatch (componentName, eventName, params) {var parent = this.$parent || this.$rootvar name = parent.$options.componentNamewhile (parent && (!name || name !== componentName)) {parent = parent.$parentif (parent) {name = parent.$options.componentName}}if (parent) {parent.$emit.apply(parent, [eventName].concat(params))}},broadcast (componentName, eventName, params) {broadcast.call(this, componentName, eventName, params)}}
}
2.number.vue
<template><div><div class="el-number-input-wrap el-input" :class="{'is-disabled': this.inputDisabled}"><input:type="inputPositive"class="el-input__inner":id="elementId":class="inputClasses":disabled="disabled"autoComplete="off"spellcheck="false":autofocus="autofocus"@focus="handleFocus"@blur="handleBlur"@input="handleInput"@change="change":readonly="readonly || !editable":name="name":value="formatterValue":placeholder="placeholder"/></div></div>
</template>
<script>
import emitter from './emitter.js'
export default {name: 'Number',componentName: 'Number',mixins: [ emitter ],inheritAttrs: false,inject: {unForm: {default: ''},unFormItem: {default: ''}},props: {value: {type: [String, Number],default: null},max: {type: Number,default: Infinity},min: {type: Number,default: -Infinity},step: {type: Number,default: 1},activeChange: {type: Boolean,default: true},isnum: {type: Boolean,default: false},disabled: {type: Boolean,default: false},autofocus: {type: Boolean,default: false},readonly: {type: Boolean,default: false},editable: {type: Boolean,default: true},name: {type: String},precision: {type: Number},elementId: {type: String},formatter: {type: F