我有一个这样的组件:
<vue-component show></vue-component>
如您所见,有一个
show
支柱。我无法使用 typeof
因为它总是 undefined
因为没有值(value)。请帮忙!
最佳答案
好吧,您将在模板中使用如下内容:
<div v-if="show">
...
</div>
如果您需要检查脚本内部,您可能知道:
if(this.show) {
和,
typeof show // will always be undefined
因为 props 也可以使用
this
访问:typeof this.show // will return Boolean as you're just passing show
// which is simply like `:show="true"`
关于javascript - 如何检查 Vue 中是否存在 prop?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53465416/