美文网首页
vue 三级联动

vue 三级联动

作者: Isaacyyy | 来源:发表于2018-10-31 11:06 被阅读0次
  <div id="example">
      <select v-model="prov">
        <option v-for="option in arr" :value="option.name">
          {{ option.name }}
        </option>
      </select>
  <select v-model="city">
        <option v-for="option in cityArr" :value="option.name">
              {{ option.name }}
        </option>
  </select>
  <select v-model="district" v-if="district">
      <option v-for="option in districtArr" :value="option.name">
          {{ option.name }}
      </option>
  </select>
 </div>








<script type="text/javascript">
    var vm = new Vue({
        el: '#example',
        data: {
            arr: arrAll,
            prov: '北京',
            city: '北京',
            district: '东城区',
            cityArr: [],
            districtArr: []
        },
        methods: {
            updateCity: function () {
                for (var i in this.arr) {
                    var obj = this.arr[i];
                    if (obj.name == this.prov) {
                        this.cityArr = obj.sub;
                        break;
                    }
                }
                this.city = this.cityArr[1].name;
            },
            updateDistrict: function () {
                for (var i in this.cityArr) {
                    var obj = this.cityArr[i];
                    if (obj.name == this.city) {
                        this.districtArr = obj.sub;
                        break;
                    }
                }
                if(this.districtArr && this.districtArr.length > 0 && this.districtArr[1].name) {
                    this.district = this.districtArr[1].name;
                } else {
                    this.district = '';
                }
            }
        },
        beforeMount: function () {
            this.updateCity();
            this.updateDistrict();
        },
        watch: {
            prov: function () {
                this.updateCity();
                this.updateDistrict();
                },
            city: function () {
                this.updateDistrict();
                }
        }
    })
</script>

vue项目中 tab切换使用echart 会有问题。 设置的宽度不生效,为100px,因为tab不切换的时候是没有宽度的。
最简单的解决方法 直接用lazy=true; 就好了
代码如下

`DKIPD7BCFATPPA9QWL8DE0.jpg
W4)I3(YY~~_T`LJOGB20QS0.png

相关文章

网友评论

      本文标题:vue 三级联动

      本文链接:https://www.haomeiwen.com/subject/xocyyftx.html