laravel - Vue共享组件未显示
问题描述
我需要一些帮助来调试一个让我发疯的问题。
我有一个以 Vue3 作为前端的 laravel 项目,使用 InertiaJS 连接到后端。
文件夹结构如下
|_resources
|__js
|___Pages
|____AddContent
|_____Index.vue
|____Home
|_____Index.vue
|___Shared
|____Footer.vue
在 Home/Index.vue 调用时,我的 Footer.vue(如下)工作正常
<div class="m-6 text-ternary-dark dark:text-ternary-light text-lg">
<div class="flex justify-between">
<Link href="/">
<i data-feather="home" class="ml-0 sm:ml-1 mr-2 sm:mr-3 w-5 sm:w-6"></i>
</Link>
<Link href="/market"><i data-feather="package" class="ml-0 sm:ml-1 mr-2 sm:mr-3 w-5 sm:w-6"></i></Link>
<Link href="/add"><i data-feather="plus-square" class="ml-0 sm:ml-1 mr-2 sm:mr-3 w-5 sm:w-6"></i></Link>
<Link href="/message"><i data-feather="send" class="ml-0 sm:ml-1 mr-2 sm:mr-3 w-5 sm:w-6"></i></Link>
<Link href="/profile"><i data-feather="user" class="ml-0 sm:ml-1 mr-2 sm:mr-3 w-5 sm:w-6"></i></Link>
</div>
</div>
</template>
<script>
import { Link } from "@inertiajs/inertia-vue3";
import feather from 'feather-icons';
export default {
components: {
Link,
},
};
</script>
主页.vue
<template>
<Header />
<div class="mb-4 text-ternary-dark dark:text-ternary-light text-lg">
<!-- The top section of homepage, reserved for hastags, news, and other features -->
<div>
<p>Top Component</p>
</div>
<!-- The rest of the homepage contents -->
<div>
<p>The Rest</p>
<div class="wrapper" v-if="blogs.length">
<div class="blog" v-for="blog in blogs" :key="blog">
<Link href="blogs/{id}/show" method="get" :data="{id: blog.id}">
<!-- <img v-bind:src="blog.image"/> -->
<small>posted by: {{ blog.id }}</small>
{{ blog.title }}
</Link>
</div>
</div>
</div>
</div>
<Footer />
</template>
<script>
import { Link } from '@inertiajs/inertia-vue3'
import Header from "../../Shared/Header.vue";
import Footer from "../../Shared/Footer.vue";
export default {
components: {
Header,
Footer,
Link
},
props: {
blogs: Object,
},
};
</script>
这是 Home/Index.vue 的外观:
然后,问题是,在 AddContent/Index.vue(下),我有与 Home/Index.vue 相同的代码来导入页脚。
<template>
<div class="mb-4 text-ternary-dark dark:text-ternary-light text-lg">
<form @submit.prevent="submit">
<label for="title">Title: </label>
<input type="text" id="title" v-model="form.title" placeholder="type something" class="rounded-full py-1 px-4"/>
<label for="body">Body: </label>
<input type="text" id="body" v-model="form.body" placeholder="type something" class="rounded-full py-1 px-4"/>
<button type="submit">Submit</button>
</form>
</div>
<Footer />
</template>
<script>
import { reactive } from "vue";
import { Inertia } from "@inertiajs/inertia";
import Footer from "../../Shared/Footer.vue";
export default {
components: {
Footer,
},
setup() {
const form = reactive({
title: null,
body: null,
});
function submit() {
Inertia.post("/", form);
}
return { form, submit };
},
};
</script>
<style scoped>
* {
outline: 1px solid red;
}
</style>
但是,在我的 AddContent/index.vue 中,页脚栏没有显示。
我不知道到底发生了什么......因为红色轮廓很好地包裹了页脚,但页脚中没有任何内容传递到 AddContent 页面。对此的任何提示将不胜感激!
解决方案
@ShayaUlman 建议通过将组件更改为布局https://inertiajs.com/pages来解决问题。
为了以后参考,如果你的布局没有出现,尝试删除或注释掉内容,重新启动npm并重新添加内容。这似乎解决了之后的问题。
推荐阅读
- python - 更新半径的用户输入而不是无限打印相同的半径
- json - JSON 中位置 0 的意外令牌 < - Three.js 和 Vue 应用程序中的 glTFLoader
- google-container-registry - 无法在 Drone 插件drone-gcr(和drone-docker)中设置上下文
- angular - 如何以角度创建动态链接按钮
- django - 带有 Jinja2 的 Django:模板搜索路径
- amazon-ecs - 如何更新和 ECS 服务添加一个额外的负载平衡,服务与之对话而不停机?
- reactjs - 自动 DynamoDB 数据库检查 | ReactJS + AWS 放大
- visual-studio-code - 更改vs代码中括号和大括号的颜色
- ruby-on-rails - 恢复数据库后,从相同的 SGID 加载 ActionText::Attachable 不再有效
- javascript - 使用 javascript 抓取网页 - 由于错误 80020101 无法完成操作