近期把 element-ui 升级到了官网最新的 2.15.7 版本,无意间发现控制台出现了 Prop being mutated: "placement" 警告,完整警告:

Prop being mutated: "placement"
▲Prop being mutated: "placement"

[Vue warn]: 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"

错误原因

锁定组件,发现是 el-date-picker 组件抛出的警告。通过在 github 上搜索,最终找到了答案

问题出在了这个 PR #21806 增加了 props placement 用来适应位置,但是之前的代码 created 时有给 placement 赋值。

this.placement = PLACEMENT_MAP[this.align] || PLACEMENT_MAP.left; 

说白了之前 placement 是 data 的对象,现在变成 props 了,然后修改就报错了

解决方案

想要解决这个问题,可以修改版本到 2.15.8

npm uninstall element-ui
npm install [email protected] -s

解决方案来自:https://github.com/ElemeFE/element/issues/21905

©版权: https://huawenzixun.com/post/5192.html

标签: 技术

你可能感兴趣

添加新评论