Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <script src="//unpkg.com/vue/dist/vue.js"></script>
<script src="//unpkg.com/element-ui@2.14.1/lib/index.js"></script>
<div id="problem">
  <h3>问题</h3>
  <el-time-select v-model="value" :picker-options="{
    start: '08:30',
    step: '00:15',
    end: '18:30'
  }" placeholder="选择时间">
  </el-time-select>
  <div>
    <iframe src="" frameborder="0" class="iframe"></iframe>
  </div>
</div>
<div id="method">
  <h3>解决方案</h3>
  <el-time-select ref="select" v-model="value" :picker-options="{
    start: '08:30',
    step: '00:15',
    end: '18:30'
  }" placeholder="选择时间">
  </el-time-select>
  <div>
    <iframe src="" frameborder="0" class="iframe2"></iframe>
  </div>
</div>
<div id="fact">
  <h3>实际解决方案</h3>
  <div ref="parent">
    嵌套了多层元素
    <div>
      <div>
        <el-time-select  v-model="value" :picker-options="{
    start: '08:30',
    step: '00:15',
    end: '18:30'
  }" placeholder="选择时间">
        </el-time-select>
      </div>
    </div>
    <el-time-select  v-model="value" :picker-options="{
    start: '08:30',
    step: '00:15',
    end: '18:30'
  }" placeholder="选择时间">
    </el-time-select>
  </div>
  <el-time-select  v-model="value" :picker-options="{
    start: '08:30',
    step: '00:15',
    end: '18:30'
  }" placeholder="选择时间">
  </el-time-select>
  <div>
    <iframe src="" frameborder="0" class="iframe3"></iframe>
  </div>
</div>
              
            
!

CSS

              
                @import url("//unpkg.com/element-ui@2.14.1/lib/theme-chalk/index.css");

.iframe {
  background-color: red;
  width: 100%;
  height: 80vh;
  margin-top: 10px
}


.iframe2 {
  background-color: blue;
  width: 100%;
  height: 80vh;
  margin-top: 10px
}
.iframe3 {
  background-color: green;
  width: 100%;
  height: 80vh;
  margin-top: 10px
}
              
            
!

JS

              
                const problemVm = {
  data() {
    return {
      value: ""
    };
  }
};
const methodVm = {
  data() {
    return {
      value: ""
    };
  },
  methods: {
    addCloseEvent() {
      const fn = () => {
        setTimeout(() => {
          const activeElement = document.activeElement;
          const selectVm = this.$refs.select
          if (activeElement.nodeName === "IFRAME") {
            selectVm.handleClose() // element-ui 统一命名的关闭下拉框方法
          }
        }, 100);
      };
      document.addEventListener("focusout", fn);
      this.$once("hook:beforeDestroy", () => {
        document.removeEventListener("focusout", fn);
      });
    }
  },
  mounted() {
    this.addCloseEvent();
  }
};
const factVm = {
  data() {
    return {
      value: "",
      closeMethods: []
    };
  },
  methods: {
    searchHandleClose (vm) {
      for (let i = 0; i < vm.$children.length; i++) {
        const sub = vm.$children[i]
        if (sub.handleClose) {
          this.closeMethods.push(sub.handleClose)
        }
        if (sub.$children.length) {
          this.searchHandleClose(sub)
        }
      }
    },
    addCloseEvent() {
      const fn = () => {
        setTimeout(() => {
          const activeElement = document.activeElement;
          if (activeElement.nodeName === "IFRAME") {
            this.closeMethods.forEach(fn => fn())
          }
        }, 100);
      };
      document.addEventListener("focusout", fn);
      this.$once("hook:beforeDestroy", () => {
        document.removeEventListener("focusout", fn);
      });
    }
  },
  mounted() {
    this.searchHandleClose(this)
    this.addCloseEvent();
  }
};
const Problem = Vue.extend(problemVm);
const Method = Vue.extend(methodVm);
const Fact = Vue.extend(factVm);

new Problem().$mount("#problem");
new Method().$mount("#method");
new Fact().$mount("#fact");


              
            
!
999px

Console