封裝餓了嗎element-ui的timepicker時(shí)候出現(xiàn)如下錯(cuò)誤:
[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: "value"
(found in <ElInput>)
warn @ vue.js?1a2a:564
(anonymous) @ vue.js?1a2a:2699
reactiveSetter @ vue.js?1a2a:864
updateChildComponent @ vue.js?d304:2468
prepatch @ vue.js?d304:3343
patchVnode @ vue.js?d304:5136
updateChildren @ vue.js?d304:5064
patchVnode @ vue.js?d304:5147
updateChildren @ vue.js?d304:5064
patchVnode @ vue.js?d304:5147
updateChildren @ vue.js?d304:5064
patchVnode @ vue.js?d304:5147
updateChildren @ vue.js?d304:5064
patchVnode @ vue.js?d304:5147
updateChildren @ vue.js?d304:5064
patchVnode @ vue.js?d304:5147
updateChildren @ vue.js?d304:5064
patchVnode @ vue.js?d304:5147
patch @ vue.js?d304:5271
Vue._update @ vue.js?d304:2303
updateComponent @ vue.js?d304:2419
get @ vue.js?d304:2756
run @ vue.js?d304:2826
flushSchedulerQueue @ vue.js?d304:2595
(anonymous) @ vue.js?d304:658
nextTickHandler @ vue.js?d304:605
vue.js?1a2a:564 [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: "readonly"
(found in <ElInput>)
封裝代碼如下:
<template>
<p class="block">
<span class="demonstration">時(shí)間</span>
<el-date-picker
v-model="date"
type="datetimerange"
placeholder="Select time range">
</el-date-picker>
</p>
</template>
<script>
export default {
name:"timepicker",
data(){
return{
date:this.dateValue
}
},
props: {
dateValue: Array
},
computed:{
}
}
</script>
使用如下:
<timepicker :date-value="date"></timepicker>
當(dāng)點(diǎn)擊時(shí)間控件選擇時(shí)間的時(shí)候,就會(huì)報(bào)錯(cuò),不點(diǎn)擊沒(méi)問(wèn)題。
求大神幫看下如何封裝帶v-model的組件。
這種錯(cuò)誤是vue2.0里有的,意思是你修改了父組件傳過(guò)來(lái)得值,你已經(jīng)使用data代替了,所以不是這個(gè)地方出的問(wèn)題,難道是傳到elementUI時(shí)出的問(wèn)題?你不給date賦值dateValue,用當(dāng)前頁(yè)面自己定義的數(shù)據(jù)呢?還會(huì)有這個(gè)問(wèn)題嗎?