简体   繁体   English

在没有路由器链接的 Laravel 8 中使用“vue-sidebar-menu”的问题

[英]Problem to use 'vue-sidebar-menu' in Laravel 8 without router-link

Please help me fix this problem.请帮我解决这个问题。 I create application using Laravel 8, Blade templates and Vue 3 components.我使用 Laravel 8、Blade 模板和 Vue 3 组件创建应用程序。 In that i have basic routing in Laravel.因为我在 Laravel 中有基本路由。 I want to add nice looking menu in admin panel https://github.com/yaminncco/vue-sidebar-menu .我想在管理面板https://github.com/yaminncco/vue-sidebar-menu中添加漂亮的菜单。

Unfortunately, I don't know how to pass my menu structure to this component.不幸的是,我不知道如何将我的菜单结构传递给这个组件。 When I use the example from the documentation I get an error当我使用文档中的示例时,出现错误

Failed to resolve component: router-link无法解析组件:路由器链接

I dont use router in Vue.我不在 Vue 中使用路由器。 I see in documentation example with Customize link with InertiaJa but i dont know how use it because i dont use and know InertiaJS.我在文档示例中看到了带有 InertiaJa 的自定义链接,但我不知道如何使用它,因为我不使用也不知道 InertiaJS。

My simple MainMenu.vue component code:我简单的 MainMenu.vue 组件代码:

<template>
<SidebarMenu  :menu="menu"></SidebarMenu>
</template>
<script>
import { SidebarMenu } from 'vue-sidebar-menu'
import 'vue-sidebar-menu/dist/vue-sidebar-menu.css'
export default {
  name: "MainMenu",
  components: {
    SidebarMenu
  },
  data() {
    return {
      menu: [
        {
          header: 'Main Navigation',
          hiddenOnCollapse: true
        },
        {
          href: '/',
          title: 'Dashboard',
          icon: 'fa fa-user'
        },
        {
          href: '/charts',
          title: 'Charts',
          icon: 'fa fa-chart-area',
          child: [
            {
              href: '/charts/sublink',
              title: 'Sub Link'
            }
          ]
        }
      ]
    }
  }
}
</script>
<style scoped>

</style>

Ok, I found a solution to the problem.好的,我找到了解决问题的方法。 Need to add own code which create\render simple link in html需要在 html 中添加创建\渲染简单链接的自己的代码

in app.js add:在 app.js 中添加:

/*remaining application code*/
import { createApp, h } from "vue";
const customLink = {
    name: 'CustomLink',
    props: ['item'],
    render() {
        return h('a', this.$slots.default())
    }
}

const app = createApp({});
app.component('custom-link', customLink)

/*remaining application code*/

and in Vue Component:在 Vue 组件中:

<SidebarMenu :menu="menu" :link-component-name="'custom-link'"></SidebarMenu>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM