vue+ivew四级联动

欢迎批评:

html部分:

 <Form
    ref="formValidate"
    :model="formValidate"
    :rules="ruleValidate"
  >
    <FormItem
      prop="bank"
      class="bank"
    >
      <Select
        v-model="formValidate.bank"
        placeholder="请选择银行"
        @on-change="change"
       
      >
        <Option
          v-for="item in bank"
          :key="item.id"
          :value="item.id"
        >{{ item.name}}</Option>
      </Select>
    </FormItem>
    <FormItem
      prop="province"
      class="province"
    >
      <Select
        v-model="formValidate.province"
        placeholder="请选择省份"
        @on-change="change1" 
      >
        <Option
          v-for="item in provinceArr"
          :key="item.id"
          :value="item.id"
        >{{ item.name}}</Option>
      </Select>
    </FormItem>
  <div>
    <FormItem
      prop="city"
      class="city"
    >
      <Select
        v-model="formValidate.city"
        placeholder="请选择城市"
        @on-change="change2" 
      >
        <Option
          v-for="item in cities"
          :key="item.id"
          :value="item.id"
        >{{ item.name}}</Option>
      </Select>
    </FormItem>
    <FormItem
      prop="branch"
      class="branch"
    >
      <Select
        v-model="formValidate.branch"
        placeholder="请选择支行" 
      >
        <Option
          v-for="item in branch"
          :key="item.id"
          :value="item.id"
        >{{ item.name}}</Option>
      </Select>
    </FormItem>
  </div>
  </Form>

js部分:

export default {
  name: 'help',
  data() {
    return {
      bank: [
        {
          id: 1,
          name: "中国建设银行",
          provinceArr: [{
            id: 11,
            name: "北京市",
            cities: [{
              id: 111,
              name: "北京市",
              branch: [{
                id: 1111,
                name: "中国建设银行北京支行"
              }]
            }]
          }, {
            id: 12,
            name: "天津市",
            cities: [{
              id: 121,
              name: "天津市",
              branch: [{
                id: 1211,
                name: "中国建设银行天津支行"
              }]
            }]
          }]
        },
        {
          id: 2,
          name: "中国银行",
          provinceArr: [
            {
              id: 21,
              name: "北京市",
              cities: [{
                id: 211,
                name: "北京市",
                branch: [{
                  id: 2111,
                  name: "中国银行北京支行"
                }]
              }]
            },
            {
              id: 22,
              name: "天津市",
              cities: [{
                id: 221,
                name: "天津市",
                branch: [{
                  id: 2211,
                  name: "中国银行天津支行"
                }]
              }]
            }]
        }
      ],
      provinceArr: "",
      cities: "",
      branch: "",
      formValidate: {},
      ruleValidate: {}
    }
  },
  methods: {
    change(val) {
      console.log('bank----------' + val)
      for (var i = 0; i < this.bank.length; i++) {
        if (val == this.bank[i].id) {
          this.provinceArr = this.bank[i].provinceArr;
        }
      }
    },
    change1(val) {
      console.log(val)
      for (var i = 0; i < this.provinceArr.length; i++) {
        if (val == this.provinceArr[i].id) {
          this.cities = this.provinceArr[i].cities;
        }
      }
    },
     change2(val) {
      console.log(val)
      for (var i = 0; i < this.cities.length; i++) {
        if (val == this.cities[i].id) {
          this.branch = this.cities[i].branch;
        }
      }
    }
  }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值