我有一個主組件和一個子組件。子組件保存創建模式的數據以及編輯模式。孩子有一個數據段如下當組件是正在使用創建模式使用相同的表單進行創建和讀取操作
data() {
return {
title: '',
description: '',
organizer: '',
startdate: '',
enddate: '',
email: '',
phone: ''
}
},
和我的創造模式是如下
<input type="text" placeholder="enter event title here" class="form-control" v-model="title">
在編輯模式下輸入,我更新在客戶端上的道具值如下,其是
props:['currentevent']
的currentevent的值正在從主部件到子組件傳遞,並且還爲當前的值正在編輯。
因此,處理的輸入值的完整代碼看起來如下
<input type="text" placeholder="enter event title here" class="form-control" v-if="currentevent" :value="currentevent.title">
<input type="text" placeholder="enter event title here" class="form-control" v-else v-model="title">
在我保存方法(在子組件),我檢查,如果currentevent爲空。如果它是空的,那麼我觸發添加代碼,否則觸發更新代碼。
問題:這是有效的,但我有一個很大的形式,必須爲每一個組件做這件事都不是一個乾淨的設計。你可以讓我知道我應該做什麼?
謝謝@rommel ..它的工作..再次感謝! :) – Gagan
@Rommel桑托爾,似乎你掌握vue.js.我需要你的幫助。看看這裏:http://stackoverflow.com/questions/41843823/how-to-display-button-link-with-vue-js –