开发者社区> 问答> 正文

vue ivew的form的动态生成lable? 400 报错

vue ivew的form的动态生成lable? 400 报错

<template>

<Form ref="formInline" :model="formInline" :label-width="110" :rules="ruleInline">

<Spin size="large" v-show="!add.isAdd && (loading || add.detailLoading)" class="base-form-loading"></Spin>

<FormItem prop="interface_resources_name" label="接口资源名称">

<Input type="text" v-model="formInline.interface_resources_name" placeholder="接口资源名称"></Input>

</FormItem>

<FormItem prop="code" label="系统编号">

<Input type="text" v-model="formInline.code" placeholder="系统编号"></Input>

</FormItem>

<FormItem label="所属分类">

<Select v-model="formInline.the_category">

<Option v-for="(t,i) in classTyoe" :value="t.id" :key="i">{{t.name}}</Option>

</Select>

</FormItem>

<FormItem prop="sort" label="排序">

<Input type="text" v-model="formInline.sort" placeholder="排序"></Input>

</FormItem>

<FormItem prop="interface_address" label="接口地址">

<Input type="text" v-model="formInline.interface_address" placeholder="接口地址"></Input>

</FormItem>

<FormItem prop="returns_format" label="返回格式">

<Input type="text" v-model="formInline.returns_format" placeholder="返回格式"></Input>

</FormItem>

<FormItem prop="request_way" label="请求方式">

<Input type="text" v-model="formInline.request_way" placeholder="请求方式"></Input>

</FormItem>

<FormItem prop="sample_request" label="请求示例">

<Input type="text" v-model="formInline.sample_request" placeholder="请求示例"></Input>

</FormItem>

<FormItem label="请求参数说明">

<child2 :formDynamic="formInline.ChildEntryAddressList"></child2>

</FormItem>

<FormItem label="返回参数说明">

<typetab :formDynamic="formInline.ChildEntryAddressList"></typetab>

</FormItem>

<FormItem label='JSON返回示例'>

<Input v-model="formInline.return_json" :rows="4" type="textarea"></Input>

</FormItem>

<FormItem label='资源备注'>

<Input v-model="formInline.resource_note" :rows="4" type="textarea"></Input>

</FormItem>

<Button type="primary" long @click="handleSubmit" :loading="submitLoading" :disabled="loading">提 交</Button>

</Form>

</template>

 

<script>

import child2 from '../../tables/baseTab'

import typetab from '../../tables/typeTab'

import _ from 'lodash'

export default {

components: {child2, typetab},

data () {

return {

formInline: {

interface_resources_name: '',

code: '',

interface_address: '',

the_category: [],

returns_format: '',

request_format: '',

request_way: '',

sample_request: '',

return_json: '',

resource_note: '',

ChildEntryAddressList: []

},

ChildEntryAddressList: [],

ruleInline: {

interface_resources_name: [

{ required: true, message: '必填项不能为空', trigger: 'blur' }

],

interface_address: [{ required: true, message: '必填项不能为空', trigger: 'blur' }],

returns_format: [{ required: true, message: '必填项不能为空', trigger: 'blur' }],

code: [{ required: true, message: '必填项不能为空', trigger: 'blur' }],

sort: [{ required: true, type: 'number', message: '必填项不能为空', trigger: 'blur' }],

request_format: [{ required: true, message: '必填项不能为空', trigger: 'blur' }],

request_way: [{ required: true, message: '必填项不能为空', trigger: 'blur' }],

sample_request: [{ required: true, message: '必填项不能为空', trigger: 'blur' }],

return_json: [{ required: true, message: '必填项不能为空', trigger: 'blur' }],

resource_note: [{ required: true, message: '必填项不能为空', trigger: 'blur' }],

the_category: [

{

type: 'array',

required: true,

message: '必填项不能为空',

trigger: 'blur'

}

]

},

loading: false,

classTyoe: [],

submitLoading: false

}

},

props: ['formValidate', 'add', 'baseUrls', 'tableName'],

mounted () {

this.init()

},

watch: {

'add.modal' (val) {

if (!val) {

this.$refs.formInline.resetFields()

} else {

this.renderForm(this.formValidate)

}

},

formValidate: {

deep: true,

handler: function (val, oldVal) {

this.renderForm(val)

}

}

},

methods: {

renderForm (obj) {

for (let attr in this.formInline) {

if (attr === 'division') {

this.formInline[attr] = obj[attr] ? obj[attr].split(',') : []

} else {

this.formInline[attr] = obj[attr] ? obj[attr] : ''

}

}

this.formInline.ChildEntryAddressList = _.cloneDeep(obj.ChildList)

},

init () {

this.loading = true

this.$ajax({

method: 'post',

url: 'api/open/ClassificationInfo/queryAll'

 

}).then(results => {

this.loading = false

this.classTyoe = results.data

})

},

handleSubmit () {

let obj = {}

let basepush = {}

basepush.main_scenic = ''

this.ChildEntryAddressList.forEach((t, i) => {

// if (t.status === 1 && t.value) {

// LsScenicBasicObj.main_scenic += t.value + ','

// }

basepush.main_scenic += t.value + ','

})

console.log('object', this.ChildEntryAddressList)

 

obj['ChildEntryAddressList'] = []

this.formInline.ChildEntryAddressList.forEach((t, i) => {

obj['ChildEntryAddressList'].push({

name: t.name,

mandatory: t.mandatory,

parameter_type: t.parameter_type,

instructions: t.instructions

})

})

console.log('object2222', this.formInline.ChildEntryAddressList)

for (let attr in this.formInline) {

if (attr === 'division') {

obj[attr] = this.formInline[attr].join(',')

} else {

obj[attr] = this.formInline[attr]

}

}

if (!this.add.isAdd && this.add.id) {

obj.id = this.add.id

}

 

this.$refs.formInline.validate(valid => {

if (valid) {

this.submitLoading = true

this.$ajax({

method: 'post',

url: this.add.isAdd ? this.baseUrls.create : this.baseUrls.update,

data: obj

})

.then(result => {

this.submitLoading = false

this.$emit('getId', result) // {...result, modal: false}

this.$Notice.success({

title: '保存成功!',

duration: 3

})

})

.catch(result => {

this.submitLoading = false

// this.$refs.upload.clearFiles()

})

} else {

this.$Message.error('请检查表单系填写是否有误!')

}

})

}

}

}

</script>

 

<style>

.base-form-loading .ivu-spin-dot {

display: inline-block;

}

</style>

 

<style lang="less" scoped>

.file-img {

position: absolute;

top: 1px;

left: 120px;

width: 30px;

height: 30px;

transition: all ease 0.5s;

&:hover {

z-index: 999999;

top: -80px;

width: 140px;

height: auto;

}

}

</style>


请求和返回的lable需要动态生成

展开
收起
爱吃鱼的程序员 2020-06-03 11:54:59 573 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    看了你的代码,暂时没看出问题,有没有什么报错或提示信息

     

    ######回复 @Trivia : 是的 返回参数和请求参数 这个是后台给的######回复 @芦荟还好 : 是在哪一步生成?是<Form-item >的label属性吗?######没有报错啊 就是lable不是动态生成的呃######

    建议安装vue devtools,可以直观的看到各个组件内的数据变化。如果是在this.formInline.ChildEntryAddressList = _.cloneDeep(obj.ChildList)这行添加lable的话,可以试一下用this.$set添加

    2020-06-03 13:13:53
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Vue.js 在前端服务化上的探索与实践 立即下载
利用编译将 Vue 组件转成 React 组件 立即下载
Vue.js在前端服务化上的实践与探索 立即下载