javascript - 使用Elementui动态新增表单提交的问题
PHP中文网
PHP中文网 2017-05-18 11:02:46
0
1
595

我使用动态新增表单做投票选项条件,用户在发布投票的时候至少需要填写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]

PHP中文网
PHP中文网

认证0级讲师

全部回复(1)
淡淡烟草味

关键代码是addDomain,贴出来

同时,在chrome的开发者工具栏中看看你提交的数据是怎样的

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!