我使用動態新增表單做投票選項條件,用戶在發布投票的時候至少需要填寫2個以上。我在提交給後台的時候獲取不到輸入的多個內容。下面是程式碼:
1.這個是動態表單
<el-form :model="condition" ref="condition" label-width="60px" class="demo-dynamic" style="padding-right:0px;">
<el-form-item
prop="cona"
label="投票条件"
>
<el-input v-model="condition.cona"></el-input>
</el-form-item>
<el-form-item
prop="conb"
label="投票条件"
>
<el-input v-model="condition.conb"></el-input>
</el-form-item>
<el-form-item
:required = false
v-for="(domain, index) in condition.domains"
label="投票条件"
:key="domain.key"
:prop="'domains.' + index + '.value'"
>
<el-input v-model="domain.value"></el-input><el-button @click.prevent="removeDomain(domain)">删除</el-button>
</el-form-item>
<el-form-item>
<el-button @click="addDomain">新增条件</el-button>
</el-form-item>
</el-form>
2.下面是vuejs程式碼部分,
data(){
return{
condition: {
domains: [{
value: ''
}],
cona: '',
conb:''
}
}
}
3.下面是提交程式碼方法,用的是postJsonp,還有其他選項判斷在裡面
//发表投票
handleThem: function () {
// 防止类型为空
if (this.themeType === 'undefined' || this.themeType === '') {
this.dialog.text = '请选择话题类型'
this.dialog.show = true
// 判断标题
} else if (this.title === 'undefined' || this.title === '') {
this.dialog.text = '请输入标题'
this.dialog.show = true
// 判断投票条件
} else if (this.condition === 'undefined' || this.condition === '') {
this.dialog.text = '请输入投票条件'
this.dialog.show = true
// 判断内容
} else if (this.editor.getContent() === 'undefined' || this.editor.getContent() === '') {
this.dialog.text = '请输入内容'
this.dialog.show = true
} else {
let postSubmit = document.getElementById('postSubmit')
if (postSubmit.disabled) return
postSubmit.value = '提交中...'
// 禁用提交按钮
postSubmit.disabled = 'true'
postJsonp(config.ajaxUrl + '/total/theme/addTheme1', {
title: this.title,
content: this.editor.getContent(),
themeType: this.themeType,
condition:this.condition,
tempFiles:this.dialogVisible,
itype:this.value,
count:this.count
}, (response) => {
if (response.ok === 1) {
postSubmit.value = '发表'
// 启动按钮
postSubmit.removeAttribute('disabled')
// 关闭弹窗
this.$emit(this.hide())
// 刷新列表
this.$emit('success')
} else {
postSubmit.value = '发表'
// 启动按钮
postSubmit.removeAttribute('disabled')
// 刷新列表
this.$emit('success')
this.dialog.text = response.msg
this.dialog.show = true
}
})
}
},
4.我提交的時候condition:[object Object]
關鍵程式碼是addDomain,貼出來
同時,在chrome的開發者工具列中看看你提交的資料是怎麼樣的