vue之用v-for循环列出element表单

<el-form-item
    v-for="(item,index) in vcardlist"
    :key="index"
    :label="item.vcardlable"
    :prop="item.vcardprop"
>
<el-input v-model="ruleForm[item.vcardprop]" clearable></el-input>
</el-form-item>
data(){
//验证邮箱的规则
    var checkEmail = (rule, value, cb) => {
      if (value) {
        const regEmail = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/;
        if (regEmail.test(value)) {
          //合法的邮箱
          return cb();
        }
        cb(new Error("请输入合法的邮箱"));
      }
    };
    //验证手机号码的规则
    var checkMobile = (rule, value, cb) => {
      const regMobile = /^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/;
      if (regMobile.test(value)) {
        //合法的手机号码
        return cb();
      }
      cb(new Error("手机号码格式不正确"));
    };
return{
ruleForm: {
        name: "", //名字
        mobile: "", //手机
        email: "", //邮箱
        company: "", //公司
        dep: "", //部门
        job: "", //职位
        address: "", //地址
        note: "", //签名
        imageUrl: "", //头像
      },
      vcardlist: [
        { vcardlable: "姓名", vcardprop: "name" },
        { vcardlable: "手机", vcardprop: "mobile" },
        { vcardlable: "邮箱", vcardprop: "email" },
        { vcardlable: "公司", vcardprop: "company" },
        { vcardlable: "部门", vcardprop: "dep" },
        { vcardlable: "职位", vcardprop: "job" },
        { vcardlable: "地址", vcardprop: "address" },
        { vcardlable: "签名", vcardprop: "note" },
      ],
rules: {
        name: [
          { required: true, message: "请输入姓名", trigger: "blur" },
          // { min: 1,  message: "长度大于1个字符", trigger: "blur" },
        ],
        mobile: [
          { required: true, message: "请输入手机号", trigger: "blur" },
          { validator: checkMobile, trigger: "blur" },
        ],
        email: [
          // { required: true, message: "请输入手机号", trigger: "blur" },
          { validator: checkEmail, trigger: "blur" },
        ],
      },
}}
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
### 回答1: 你可以在Vue中使用v-for指令来循环生成一行三列的列表。具体步骤如下: 1. 在Vue的data中定义一个数组,包含要显示的数据。 2. 在HTML模板中使用v-for指令,循环遍历数组,并使用CSS样式控制每个数据项的位置。 例如,以下是一个简单的代码示例: ```html <template> <div class="container"> <div class="row"> <div class="col-md-4" v-for="(item, index) in items" :key="index"> <div class="card"> <div class="card-body"> <h5 class="card-title">{{ item.title }}</h5> <p class="card-text">{{ item.description }}</p> </div> </div> </div> </div> </div> </template> <script> export default { data() { return { items: [ { title: 'Item 1', description: 'This is the first item.' }, { title: 'Item 2', description: 'This is the second item.' }, { title: 'Item 3', description: 'This is the third item.' }, { title: 'Item 4', description: 'This is the fourth item.' }, { title: 'Item 5', description: 'This is the fifth item.' }, { title: 'Item 6', description: 'This is the sixth item.' } ] } } } </script> <style> .container { margin: 20px auto; } .card { margin-bottom: 20px; } </style> ``` 在上面的代码中,我们定义了一个包含六个数据项的数组,并使用v-for指令循环遍历每个数据项。使用Bootstrap的栅格系统,我们将每个数据项放在一个具有col-md-4类的div中,以实现一行三列的效果。最后,我们使用CSS样式设置卡片的边距。 ### 回答2: 在Vue中,可以使用v-for指令来循环渲染一行三列的列表。 首先,在Vue组件中定义一个数组,里面包含要循环渲染的数据,比如: ``` data() { return { items: [1, 2, 3, 4, 5, 6] } } ``` 接下来,在模板中使用v-for指令来循环渲染列表,使用v-bind指令来绑定每个项的数据,比如: ``` <div> <div v-for="item in items" :key="item"> {{ item }} </div> </div> ``` 上述代码中,v-for指令会遍历items数组中的每一项,并将当前项的值赋给item变量,然后在循环体中渲染当前项的值。使用:key绑定每一项的唯一标识,以提高渲染性能。 为了实现一行三列的布局,可以使用CSS来设置每个项的宽度为33.33%(或根据实际需求设置),并设置适当的样式,比如: ``` <style> .item { width: 33.33%; display: inline-block; text-align: center; } </style> ``` 最后,将以上代码整合在Vue组件中,就可以在浏览器中看到一行三列的列表。每个项的宽度为33.33%,并按照数组中的值依次渲染。 以上就是在Vue中实现一行三列列表的简单方式,通过v-for指令和CSS样式来实现。根据具体需求,还可以进一步扩展和定制列表的样式和布局。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

办法总比困难多多

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值