uni-app:v-for里获取input的值:@input方法

v-for里获取input的值:

<!-- 个人 -->
<template>
  <view>
    <view class="person">
      <view v-for="(item, index) in personMsg" :key="index">
        <!-- 判断类型 -->
        <template v-if="item.type == 'position'">
          <view class="flex person_item">
            <text>{{ item.name }}</text>
            <view
              class="downCheck flex"
              @tap="chooseLocal($event, item.dataValue)"
            >
              <view
                class="flex justify-center align-center"
                style="width: 368rpx"
              >
                <view> {{ formData[item.dataValue] }}</view>
              </view>

              <u-icon name="map" style="margin-right: 22rpx"></u-icon>
            </view>
          </view>
        </template>
        <template v-else>
          <!-- -->
          <view class="flex align-center person_item">
            <text>{{ item.name }}</text>

            <input
              class="downCheck"
              @input="inputData($event, item.dataValue)"
            />
          </view>
        </template>
      </view>
    </view>
 

    <button class="nextBtn" @tap="nextStep()">下一步</button>
  </view>
</template>

<script>
export default {
  data() {
    return {
      formData: {
        nameValue: "", //输入框里的值
        sexValue: "",
        ageValue: "",
        telValue: "",
        potionValue: "",
        idValue: "",
        camaraPath: "",
        idPicPath: "",
      },
      personMsg: [
        {
          name: "姓名",
          icon: "none",
          type: "input",
          dataValue: "nameValue",
        },
        {
          name: "性别",
          icon: "none",
          type: "input",
          dataValue: "sexValue",
        },
        {
          name: "年龄",
          icon: "none",
          type: "input",
          dataValue: "ageValue",
        },
        {
          name: "电话",
          icon: "none",
          type: "input",
          dataValue: "telValue",
        },
        {
          name: "公司地址",
          icon: "none",
          type: "position",
          dataValue: "potionValue",
        },
        {
          name: "身份证号",
          icon: "none",
          type: "input",
          dataValue: "idValue",
        },
      ],
    };
  },

  methods: {
    nextStep() {
      //将数据传给父组件check
   
      this.$emit("personData", this.formData);
    },
    inputData(event, dataValue) {
      // var value = event.target.value;
      this.formData[dataValue] = event.target.value;
    },
  },
};
</script>
<style lang='scss' scoped>

  • 我的input是通过v-for遍历生成的,给@input根据配置项来传参的
    就可以实现将每个input里的值存放在formData里面
  • 核心代码:@input="inputData($event, item.dataValue)"
 inputData(event, dataValue) {
      // var value = event.target.value;
      this.formData[dataValue] = event.target.value;
    },
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值