laravel - vue 警告:无效的道具:道具“modalState”的类型检查失败。预期布尔值,得到函数
问题描述
我遇到了这个警告,但我不明白。我已经搜索过 StackOverflow 并且有很多帖子,但它们都是不同的,并不能解决我的问题。我读了这个通用的,我想我已经实现了提到的解决方案。警告仍然显示在控制台中。这是我的组件:
<template>
<div>
<p>Vakken</p><input id="plusButton" type="button" value="+" @click = "openAddSubject">
<table>
<th>
<tr>
<td>Afkorting</td>
<td>Beschrijving</td>
<td>Geblokt</td>
<td>Kleur</td>
<td></td>
</tr>
</th>
<tbody>
<tr v-for="subject in subjects" :key = "subject.abbr">
<td>{{subject.abbr}}</td>
<td>{{subject.desc}}</td>
<td>{{subject.blocked}}</td>
<td>{{subject.color}}</td>
</tr>
</tbody>
</table>
<add-subject :modal-state="addSubjectOpen" />
</div>
</template>
<script>
import { mapGetters } from 'vuex'
import AddSubject from './AddSubject.vue'
export default {
components: { AddSubject },
name: "Subjects",
data(){
return{
addSubjectOpen:Boolean
}
},
mounted(){
this.addSubjectOpen = false
},
methods: {
openAddSubject(){
this.addSubjectOpen = true
}
},
}
</script>
单击按钮时,通过方法 openAddSubject 将 addSubjectOpen 的值设置为 true。的 prop modal-state 设置为 true 并显示模态。addSubjectopen 的类型是布尔值。
这是 AddSubject.Vue 的代码
<template>
<div class="modal" :class="modalState?'is-active':''" >
<div class="modal-background"></div>
<div class="modal-card">
<header class="modal-card-head">
<p class="modal-card-title">Modal title</p>
<button class="delete" aria-label="close"></button>
</header>
<section class="modal-card-body" id = "modal">
<!-- Content ... -->
Gewoon wat tekst
</section>
<footer class="modal-card-foot">
<button class="button is-success">Opslaan</button>
<button class="button">Annuleren</button>
</footer>
</div>
</div>
</template>
<script>
import {mapGetters} from 'vuex'
export default {
name: 'AddSubject',
props: {
modalState:Boolean,
},
}
</script>
同样,道具 modalState 的类型肯定设置为布尔值。那么为什么它作为函数传递呢?顺便说一句,组件按预期工作,只是控制台中的警告让我感到困扰。
解决方案
data() {
return {
addSubjectOpen: false // or true, depending on needs
}
},
推荐阅读
- windows - 如何在 Windows 10 上将 DPI 比例设置为小于 100% - 使用多个显示器
- css - 如何使用 CSS 合并和填充两个圆圈中的颜色
- r - 将新数据插入表中
- postgresql - Postgres - 使用 unnest 是否可以查询未嵌套的每行?
- javascript - 在css中的下一行重叠悬停弹出窗口
- html - 按钮上的背景图像
- java - 如何模拟 Kafka AdminClient 以返回主题?
- json - 如何在 kotlin 中调试生成的 API - responseBody 仅支持 JSON 正文错误
- bash - IntelliJ IDE - 无法从 IDE 内的终端运行 Maven(路径已设置)
- javascript - 当 .jsx 和 .js 文件在同一个文件夹中时,VSCode goToDefenition 不起作用