Element-ui 日期组件ElDatePicker
报错Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop's value. Prop being mutated: "placement"
这个报错并没有影响实际操作,但是看着很难受
解决
main.js加入代码
import Vue from 'vue'
import Element from 'element-ui'
function RepairProps(cmp) {
(cmp.mixins || []).forEach(mixin => {
if (mixin.props && mixin.props.placement) {
const defaultValue = mixin.props.placement.default
mixin.data = new Proxy(mixin.data, {
apply(target, thisArg, argArray) {
const res = Reflect.apply(target, thisArg, argArray)
return {
...(res || {}),
placement: defaultValue
}
}
})
delete mixin.props.placement
}
if (mixin.mixins && mixin.mixins.length > 0) {
RepairProps(mixin)
}
})
}
RepairProps(Element.DatePicker)
RepairProps(Element.TimePicker)
RepairProps(Element.TimeSelect)
Vue.use(Element, {
size: 'medium'
})
网友评论