<p>您遇到的问题可能是因为没有正确设置 <code>v-if</code> 和 <code>v-else</code> 的条件。在您提供的代码中,<code>inputVisible</code> 控制着 Input 和 Button 的显示。要确保 Input 和 Button 能够渲染,<code>inputVisible</code> 的值需要为 <code>true</code>。您可以尝试以下步骤来排查问题:</p>
<ol>
  <li><strong>检查 <code>inputVisible</code> 的值:</strong> 使用浏览器开发者工具或打印语句,查看 <code>inputVisible</code> 的值是否为 <code>true</code>。如果值为 <code>false</code>,则需要找到原因并将其设置为 <code>true</code>。</li>
  <li><strong>确认 <code>inputVisible</code> 的更新逻辑:</strong> 检查您的代码中是否设置了更新 <code>inputVisible</code> 的逻辑。例如,您可能需要在某个事件发生时将其设置为 <code>true</code>,例如点击一个按钮或其他操作。</li>
  <li><strong>验证其他条件:</strong>  除了 <code>inputVisible</code> 外,还可能存在其他条件影响 Input 和 Button 的显示。检查您的代码中是否有其他条件语句可能会阻止 Input 和 Button 的渲染。</li>
</ol>
<p>以下是示例代码,展示了如何正确设置 <code>inputVisible</code>:</p>
<pre>
<code>
<template>
  <el-popover placement='bottom' :width='245' trigger='hover' v-for='(item, index) in uploadRes' :key='index'>
    <template #reference>
      <el-tag round color='#ffffff' closable :disable-transitions='false' @close='handleClose(index)'>
        {{ item.name }}
      </el-tag>

      <el-input v-if='inputVisible' ref='InputRef' v-model='inputValue' size='small'
        @keyup.enter='handleInputConfirm(index)' @blur='handleInputConfirm(index)' style='width: 65px;' />
      <el-button v-else size='small' @click='showInput' style='width: 65px;'>
        添加标签
      </el-button>
    </template>
    <template #default>
      <div class='identify-content'>
        <el-avatar class='animal-avatar' :size='60' :src='item.url' />
        <p class='animal-name'>
          {{ item.name }}
        </p>

        <p class='animal-desc'>
          {{ item.baike_info.description }}
        </p>
        <p class='animal-baike'>
          <!-- {{}} -->
          <a :href='item.baike_info.baike_url' target='_blank'>了解更多</a>
        </p>
      </div>
    </template>
  </el-popover>
</template>

<script>
export default {
  data() {
    return {
      inputVisible: false,
      // ... other data
    };
  },
  methods: {
    showInput() {
      this.inputVisible = true;
    },
    // ... other methods
  }
};
</code>
</pre>
<p>在上面的示例中,当点击“添加标签”按钮时,<code>showInput</code> 方法会被触发,将 <code>inputVisible</code> 设置为 <code>true</code>,从而显示 Input 和 Button。您可以根据您的实际需求修改代码,确保 <code>inputVisible</code> 在需要时被设置为 <code>true</code>。</p>
<p>如果以上方法都无法解决问题,请提供更多代码细节,以便更准确地排查问题。</p>
Element UI Popover 渲染问题:Input 和 Button 不显示的解决方法

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

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