vue属性不是传递给儿童组件的

发布于 2025-01-31 07:08:32 字数 513 浏览 0 评论 0原文

我无法使它起作用似乎很荒谬,但是当将道具传递给子部门时,道具的价值永远不会改变,而disablefootertext始终是错误的。我做错了吗?

父母:

<MyChildComponent :disableFooterText="true">

孩子:

<MyCustomDropdown :footerText="footerText">

props: {
  disableFooterText: {
    default: false,
    type: Boolean
  },
}

computed: {
  footerText() {
    if (this.disableFooterText) { // always false
      return '';
    }
    return 'Lorem impsum';    // always returns this value
  },
}

It seems ridiculous that I can't get this to work, but when passing a prop to a child component, the value of the prop never actually changes and disableFooterText is always false. Am I doing something wrong?

Parent:

<MyChildComponent :disableFooterText="true">

Child:

<MyCustomDropdown :footerText="footerText">

props: {
  disableFooterText: {
    default: false,
    type: Boolean
  },
}

computed: {
  footerText() {
    if (this.disableFooterText) { // always false
      return '';
    }
    return 'Lorem impsum';    // always returns this value
  },
}

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

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

发布评论

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

评论(2

琴流音 2025-02-07 07:08:32

尝试使用kebab-case prop:

const app = Vue.createApp({})

app.component('my-child-component', {
  template: `
    <div>
      <p>{{numResultsText}}</p>
    </div>
  `,
  props: {
    disableFooterText: {
      type: Boolean,
      default: false,
    },
  },
  computed: {
    numResultsText() {
      if (this.disableFooterText) { // always false
        return this.disableFooterText;
      }
      return 'Lorem impsum';    // always returns this value
    },
  },
})

app.mount('#demo')
<script src="https://cdn.jsdelivr.net/npm/vue@3/dist/vue.global.prod.js"></script>
<div id="demo">
   <my-child-component :disable-footer-text="true" />
</div>

Try with kebab-case prop:

const app = Vue.createApp({})

app.component('my-child-component', {
  template: `
    <div>
      <p>{{numResultsText}}</p>
    </div>
  `,
  props: {
    disableFooterText: {
      type: Boolean,
      default: false,
    },
  },
  computed: {
    numResultsText() {
      if (this.disableFooterText) { // always false
        return this.disableFooterText;
      }
      return 'Lorem impsum';    // always returns this value
    },
  },
})

app.mount('#demo')
<script src="https://cdn.jsdelivr.net/npm/vue@3/dist/vue.global.prod.js"></script>
<div id="demo">
   <my-child-component :disable-footer-text="true" />
</div>

对你而言 2025-02-07 07:08:32

尝试kebab case @nikola pavicevic要求您做,或尝试v-bind =“ {disableFooterText:true}”

Try kebab case as @Nikola Pavicevic asked you to do, or try a v-bind="{ disableFooterText: true }".

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