【vue】动态添加表单input

html:

 <FormItem>
	<Row  v-for="(item,index) in formData.peers" >
		<Col span="10" style="margin-bottom: -10px;" >
               <FormItem >
        			 <Input  size="small"   v-model="formData.peers[index]"   placeholder="peers"></Input>
              </FormItem>
       </Col>
        <Col span="1" offset="1" style="margin-bottom: -10px;">
                 <Button type="dashed" size="small" icon="md-close"  @click="delPeer(index)" ></Button>
           </Col>
      </Row>
</FormItem>
<FormItem>
      <Row>
            <Col span="10" offset="7">
                <Button type="dashed" size="small" long   @click="addPeer" icon="md-add">添加</Button>
            </Col>
      </Row>
</FormItem>

script:

 data () {
      return {
          formData: {
              peers:[""],
       	},
}

addPeer(){
      this.formData.peers.push('')
  },
 delPeer(index){
      this.formData.peers.splice(index)
  },

猜你喜欢

转载自blog.csdn.net/qq_39583930/article/details/89705418