<template>
  <div class="blue-div" :style="{ height: divHeight }"></div>
</template>
<script setup>
import { ref } from 'vue';

const divHeight = ref('100%');

function setDivHeight() {
  divHeight.value = window.innerHeight + 'px';
}

window.addEventListener('resize', setDivHeight);

function onDestroy() {
  window.removeEventListener('resize', setDivHeight);
}

onMounted(() => {
  setDivHeight();
});

export { divHeight, onDestroy };
</script>
<style scoped>
.blue-div {
  background-color: blue;
  border-radius: 30px;
}
</style>
用框架插入一个div要求样式蓝色背景圆角30高度100生成vue3生成vue3格式 script setup代码要求所有方法或箭头函数都用function定义要求所有变量为ref响应式无需任何文字说明只要源码即可

原文地址: https://www.cveoy.top/t/topic/bcuy 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录