在vue页面中

<template>
  <div style="height: 600px">
    <codemirror
      ref="myCm"
      v-model="myCode"
      :options="cmOptions"
      class="code"
    />
  </div>
</template>

设置指定高度

this.editor = this.$refs.myCm.codemirror;
// 设置codemirror高度为600
this.editor.setSize('auto', 600);

随屏幕高度变化

// 监听屏幕
mounted() {
    let that = this;
    that.clientHeight = `${document.documentElement.clientHeight}`;//获取浏览器可视区域高度
    // // 获取codemirror对象
    that.editor = this.$refs.myCm.codemirror;
    // // 设置codemirror高度
    that.editor.setSize('auto',this.clientHeight - 105);
    
    // 监听屏幕
    window.onresize = function () {
      that.clientHeight = `${document.documentElement.clientHeight}`;
      // 设置代码区域高度
      that.editor.setSize('auto',parseFloat(that.clientHeight) - 105);
    }
  },
Logo

前往低代码交流专区

更多推荐