javascript - vue封裝餓了嗎element-ui的時間控制el-date-picker報錯(v-model元件封裝)
漂亮男人
漂亮男人 2017-05-19 10:11:10
0
1
1910

封裝餓了嗎element-ui的timepicker時候出現如下錯誤:

[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">时间</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>

當點擊時間控制選擇時間的時候,就會報錯,不點擊沒問題。
求大神幫看下如何封裝帶有v-model的組件。

漂亮男人
漂亮男人

全部回覆(1)
仅有的幸福

這種錯誤是vue2.0裡有的,意思是你修改了父元件傳來得值,你已經使用data代替了,所以不是這個地方出的問題,難道是傳到elementUI時出的問題?你不給date賦值dateValue,用目前頁面自己定義的資料呢?還會有這個問題嗎?

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板