yuthen 2024-10-05 17:09 采纳率: 25%
浏览 54
已结题

使用element进行布局设置但最终网页显示的布局错乱

用element官网的代码尝试了一下,代码如下:

<script setup>
import { User, Lock } from '@element-plus/icons-vue'
import { ref } from 'vue'
</script>
<template>
    <el-row>
      <el-col :span="24"><div class="grid-content ep-bg-purple" style="background-color:chartreuse"/></el-col>
    </el-row>
    <el-row>
      <el-col :span="12"><div class="grid-content ep-bg-purple" style="background-color: blue"/></el-col>
      <el-col :span="12"><el-input v-model="input"  placeholder="Please input" /></el-col>
    </el-row>
    <el-row>
      <el-col :span="8"><div class="grid-content ep-bg-purple" style="background-color: blue"/></el-col>
      <el-col :span="8"><div class="grid-content ep-bg-purple-light" style="background-color: blueviolet" /></el-col>
      <el-col :span="8"><div class="grid-content ep-bg-purple" style="background-color: cadetblue" /></el-col>
    </el-row>
    <el-row>
      <el-col :span="6"><div class="grid-content ep-bg-purple" /></el-col>
      <el-col :span="6"><div class="grid-content ep-bg-purple-light" /></el-col>
      <el-col :span="6"><div class="grid-content ep-bg-purple" /></el-col>
      <el-col :span="6"><div class="grid-content ep-bg-purple-light" /></el-col>
    </el-row>
    <el-row>
      <el-col :span="4"><div class="grid-content ep-bg-purple" /></el-col>
      <el-col :span="4"><div class="grid-content ep-bg-purple-light" /></el-col>
      <el-col :span="4"><div class="grid-content ep-bg-purple" /></el-col>
      <el-col :span="4"><div class="grid-content ep-bg-purple-light" /></el-col>
      <el-col :span="4"><div class="grid-content ep-bg-purple" /></el-col>
      <el-col :span="4"><div class="grid-content ep-bg-purple-light" /></el-col>
    </el-row>
  </template>
  
  <style lang="scss">
  .el-row {
    margin-bottom: 20px;
  }
  .el-row:last-child {
    margin-bottom: 0;
  }
  .el-col {
    border-radius: 4px;
  }
  
  .grid-content {
    border-radius: 4px;
    min-height: 36px;
  }
  </style>

官网提供的效果如下:

img

网页显示的布局如下:

img

F12调出控制台后显示的似乎又是对的:

img


这种情况是由什么原因引起的呢?

  • 写回答

2条回答 默认 最新

  • 一轮明月照丘壑 2024-10-05 17:10
    关注

    以下回复参考:皆我百晓生券券喵儿等免费微信小程序作答:

    从你提供的代码和描述来看,你的 Vue.js 和 Element Plus 布局代码应该能够按照预期工作。然而,你遇到的问题似乎与 Vue 的渲染和组件属性有关。错误提示 "[Vue warn]: Property 'input' was accessed during render but is not defined on instance." 表示在渲染过程中访问了未定义的属性 'input'。这可能是由于 'input' 属性没有正确初始化或者在你的组件上下文中不存在。请确保在你的 Vue 组件中正确定义和初始化 'input' 属性。

    你可以尝试在 <script> 标签中的 setup 函数里添加 input 的定义和初始化,例如:

    import { ref } from 'vue';
    
    export default {
      setup() {
        const input = ref(null); // 或者初始化为一个空字符串:const input = ref('');
        return { input };
      },
      // 其他代码...
    };
    

    然后,确保在你的模板中正确地使用了 v-model 指令绑定这个 input 属性:

    <el-input v-model="input" placeholder="Please input" />
    

    此外,请检查你的样式和布局设置是否正确。确保你的 CSS 类和样式规则适用于你的布局需求。如果你使用的是 Element Plus 的栅格系统,确保你正确地使用了 el-rowel-col 组件,并且它们的 span 属性设置正确。如果你仍然遇到问题,请提供更多的代码细节或错误信息,以便我能更准确地帮助你解决问题。

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 10月6日
  • 创建了问题 10月5日