vue.js - [Vue 警告]:解析组件失败,可能导入错误
问题描述
我使用 Vue CLI 制作了一个 Vue3 项目,并且在同一个文件夹('./components/')中有一个父组件('ReactionTimer')和一个子组件('Block')。我尝试将“Block”导入“ReactionTimer”,但出现以下错误:
[Vue warn]: Failed to resolve component: Block at ReactionTimer
反应计时器.vue
<template>
<h1>Reaction Timer</h1>
<button @click="startTimer" :disabled="isTimerOn">Play</button>
<Block v-if="isTimerOn" :delay="delay" />
</template>
<script>
import Block from '../components/Block'
export default {
name: 'ReactionTimer',
components: {},
data() {
return {
isTimerOn: false,
delay: null
}
},
methods: {
startTimer() {
this.delay = 2000 + Math.random() * 5000;
this.isTimerOn = true
//console.log(this.delay)
}
}
}
</script>
块.vue
<template>
<div class="block">
click me
</div>
</template>
<script>
export default {
props: 'delay'
}
</script>
<style>
.block {
width: 400px;
border-radius: 20px;
background: green;
color: aliceblue;
text-align: center;
padding: 100px 0;
margin: 40px auto;
}
</style>
我尝试了
import Block from '../components/Block'
import Block from '../components/Block.vue'
import Block from './Block'
import Block from './Block.vue' 的每种组合
解决方案
您应该将其添加到components
选项:
...
<script>
import Block from '../components/Block.vue'
export default {
name: 'ReactionTimer',
components: {Block },
...
推荐阅读
- python - 如何在参数解析器中将路径传递到图像目录?
- visual-studio - 如何在 C++ 中创建 CMYK 模式图像?
- linux - 将命令树的结果导出到带有列的 csv 文件中
- mysql - 查询从具有添加约束的单个列中获取不同的对
- python - 以更有效的方式删除 blob 中的文件夹
- swiftui - SwiftUI PickerView 与工作回调如何?
- angular - Nebular - 登录后未正确获取令牌有效负载
- php - 有没有办法在 OctoberCms 中设置特定 CMS 页面的用户权限?
- python - 如何创建同一类的多个对象,每个对象内部都有一个无限循环
- python - 如何将提交的日期规范化为 UTC 格式 (2019-10-29T02:20:30.45Z) [这不是重复的问题,请阅读整个问题一次]