admin管理员组文章数量:1405369
When I use I use the <inertia-link>
the test.vue
child ponent does not render but it renders if I remove those tags. Any ideas as to what I am doing wrong?
test.vue
<template>
<div>
<div class="p-6 sm:px-20 bg-white border-b border-gray-200">
<div>
<b-logo class="block h-12 w-auto" />
</div>
<div class="mt-1 text-2xl">
{{ $page.user.first_name }} {{ $page.user.last_name }}
</div>
<inertia-link :href="#">
test-link
</inertia-link>
</div>
</div>
</template>
<script>
import BLogo from './BLogo'
export default {
ponents: {
BLogo,
},
}
</script>
This ponent is used in another .vue file with <my-test />
This is being done in laravel 8. Also, I have noticed that if I use the <inertia-link>
tag in the parent vue then it shows up. So the tag works.
(and I think it is used by the default Jetstream profile pages).
When I use I use the <inertia-link>
the test.vue
child ponent does not render but it renders if I remove those tags. Any ideas as to what I am doing wrong?
test.vue
<template>
<div>
<div class="p-6 sm:px-20 bg-white border-b border-gray-200">
<div>
<b-logo class="block h-12 w-auto" />
</div>
<div class="mt-1 text-2xl">
{{ $page.user.first_name }} {{ $page.user.last_name }}
</div>
<inertia-link :href="#">
test-link
</inertia-link>
</div>
</div>
</template>
<script>
import BLogo from './BLogo'
export default {
ponents: {
BLogo,
},
}
</script>
This ponent is used in another .vue file with <my-test />
This is being done in laravel 8. Also, I have noticed that if I use the <inertia-link>
tag in the parent vue then it shows up. So the tag works.
(and I think it is used by the default Jetstream profile pages).
Share Improve this question edited Sep 18, 2020 at 18:54 matt asked Sep 18, 2020 at 18:34 mattmatt 2,10718 silver badges46 bronze badges 7-
Is
inertia-link
globally registered? Any console errors? – tony19 Commented Sep 18, 2020 at 18:45 -
1
Your :href="#" prop looks off, since that's trying to bind the href property to the evaluation of the expression
#
which likely throws a syntax error. You should see an error in the dev console saying something similar. – Robert Nubel Commented Sep 18, 2020 at 18:45 - @tony19 yes. It is part of the laravel 8. Installation – matt Commented Sep 18, 2020 at 18:50
- @RobertNubel no errors. – matt Commented Sep 18, 2020 at 18:51
-
If you're not seeing errors for
:href="#"
(which is not a valid binding), there are likely other errors that are lost to you. I'd try to resolve the log issue first, as the console log is a vital troubleshooting tool. – tony19 Commented Sep 18, 2020 at 18:54
3 Answers
Reset to default 4if you are using the below code for Vue3 from inertiajs office site:
import { createApp, h } from 'vue'
import { createInertiaApp } from '@inertiajs/inertia-vue3'
createInertiaApp({
resolve: name => require(`./Pages/${name}`),
setup({ el, App, props, plugin }) {
createApp({ render: () => h(App, props) })
.use(plugin)
.mount(el)
},
})
then u have to add the Link ponent like so:
import { createApp, h } from 'vue';
import { createInertiaApp, Link } from '@inertiajs/inertia-vue3';
createInertiaApp({
resolve: name => require(`./Pages/${name}`),
setup({ el, App, props, plugin }) {
createApp({ render: () => h(App, props) })
.use(plugin)
.ponent('inertia-link', Link)
.mount(el)
},
});
after that inertia-link ponent should work should work.
First verify if you have intalled the dependencies
npm install @inertiajs/inertia @inertiajs/inertia-vue
or
yarn add @inertiajs/inertia @inertiajs/inertia-vue
Initialize app
Next, update your main JavaScript file to boot your Inertia app. All we're doing here is initializing the client-side framework with the base Inertia page ponent.
import { InertiaApp } from '@inertiajs/inertia-vue'
import Vue from 'vue'
Vue.use(InertiaApp)
const app = document.getElementById('app')
new Vue({
render: h => h(InertiaApp, {
props: {
initialPage: JSON.parse(app.dataset.page),
resolveComponent: name => require(`./Pages/${name}`).default,
},
}),
}).$mount(app)
then if you need a Code splitting, follow the next steps https://inertiajs./client-side-setup#code-splitting
I had this issue and it almost made me crazy. This is how I figured it out. <inertia-link>
is a custom link and Vue tries to find if it corresponds to a registered ponent. If Vue does not find the mponent it flags the warning
Here is what you need to do to resolve this issue.
Import Link from Vue adapter of Inertia like this in your app.js
import { Link } from '@inertiajs/inertia-vue'
Register the Link as a ponent with Vue after you have imported both Vue and Link like this in your same app.js
Vue.ponent('inertia-link', Link)
Try in your templates and should work fine.
PS:- I was using Vue2
本文标签: javascriptVue component does not render when I use ltinertialinkgt tagStack Overflow
版权声明:本文标题:javascript - Vue component does not render when I use <inertia-link> tag - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744895085a2631016.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论