VUE V-BIND:班级返回无效值

发布于 2025-01-30 22:20:09 字数 892 浏览 0 评论 0原文

我正在Vue编写一个应用程序,并且我的行为不正确,尤其是我的行:class = require? 'require':''返回字符串'quirect'即使要求的值为false,问题是什么?

<template>
  <custom-label label="Название">
    <input
        class="text_input"
        :class="require ? 'require' : ''"
        :value="$attrs.value" @input="$emit('input', $event.target.value)"
        placeholder="Матрица всея барановичского района"
    />
  </custom-label>
</template>

<script>
export default {
  name: "InputText",
  components: {CustomLabel},
  computed: mapState({ state: state => state }),
  props: {
    require: Boolean
  }
};
</script>

以下是devtools

“

I am writing an application at vue and I am getting incorrect behavior, in particular my line :class=require ? 'require' : '' returns the string 'require' even when the value of require is false, what is the problem?

<template>
  <custom-label label="Название">
    <input
        class="text_input"
        :class="require ? 'require' : ''"
        :value="$attrs.value" @input="$emit('input', $event.target.value)"
        placeholder="Матрица всея барановичского района"
    />
  </custom-label>
</template>

<script>
export default {
  name: "InputText",
  components: {CustomLabel},
  computed: mapState({ state: state => state }),
  props: {
    require: Boolean
  }
};
</script>

Below are screenshots from devtools

HTML

vue dev-tools

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

多情癖 2025-02-06 22:20:09

使用:class =“ {require}”而不是。

Use :class="{ require }" instead.

北方。的韩爷 2025-02-06 22:20:09

在stackoverflow上写了问题之前,我花了3个小时。一旦我发布了这个问题,几分钟后,我意识到我在全球区域中具有要求的功能,例如,

<img :src="require('./img.png')" />

这是一个非常愚蠢的错误,但我希望有人也遇到它将能够在我的答案的帮助下避免它。

I spent 3 hours on this before writing the question on StackOverflow. As soon as I published the question, after a few minutes I realized that I have a require function in the global area, which is needed for example for images

<img :src="require('./img.png')" />

this is a very stupid mistake, but I hope someone who also encounters it will be able to avoid it with the help of my answer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文