在故事书中实施惯性链接

发布于 2025-02-13 20:32:59 字数 1267 浏览 0 评论 0原文

嗨,我正在尝试故事书,到目前为止喜欢它!

我的问题是,我在我的Laravel应用程序(惯性)中实施它。 Im trying to render a navigation link component, which uses the inertia links wrapper: https://inertiajs.com/links

该组件在故事书中注册,但没有渲染,因为惯性链接代替了HTML 代码。有没有办法在故事书中导入惯性链接,从而使渲染成为可能?

如果我通过检查将HTML中的标签移动到锚定标签(),则组件渲染。这告诉我,确实是惯性链接,这让我头疼。

我已经尝试了一段时间,我也尝试搜索SOM时间,但是我根本找不到答案:(

我会让您更新。

如果我有新发现, 我发现控制台显示了此错误,这进一步使我的假设是惯性链接组件:

[Vue warn]: Failed to resolve component: Link
If this is a native custom element, make sure to exclude it from component resolution via compilerOptions.isCustomElement. 
  at <AppNavLink href="/" > 

vue组件的代码:

  <Link
    class="font-medium uppercase hover:text-blue-600 dark:hover:text-blue-400"
    :class="{
      ' text-blue-500 hover:text-blue-500 dark:hover:text-blue-500': active,
    }"
  >
    <slot />
  </Link>
</template>

<script>
export default {
  props: {
    active: Boolean,
  },
}
</script>

故事:

import NavLink from '../resources/js/components/ui/AppNavLink.vue'
import { Link } from '@inertiajs/inertia-vue3'

//
              

Hi im trying out storybook, loving it so far!

My issue is that im implementing it in my Laravel app, with inertia. Im trying to render a navigation link component, which uses the inertia links wrapper: https://inertiajs.com/links

The component is registered in storybook, but does not render, because the of the inertia-link replacing the html in the code. Is there a way to import the inertia link in storybook, making rendering possible?

If I manually change the tag in the html via inspection to an anchor tag (), the component renders. Which tells me that it is, indeed the inertia-link, giving me a headache.

I have tried for some time now, I also tried searching for som time, but I simply can't find an answer :(

Will keep you updated if I make new discoveries.

Edit
I discovered that the console displays this error, which further makes my assumption that its the inertia-link component:

[Vue warn]: Failed to resolve component: Link
If this is a native custom element, make sure to exclude it from component resolution via compilerOptions.isCustomElement. 
  at <AppNavLink href="/" > 

The code of the vue component:

  <Link
    class="font-medium uppercase hover:text-blue-600 dark:hover:text-blue-400"
    :class="{
      ' text-blue-500 hover:text-blue-500 dark:hover:text-blue-500': active,
    }"
  >
    <slot />
  </Link>
</template>

<script>
export default {
  props: {
    active: Boolean,
  },
}
</script>

The story:

import NavLink from '../resources/js/components/ui/AppNavLink.vue'
import { Link } from '@inertiajs/inertia-vue3'

//???? This default export determines where your story goes in the story list
export default {
  /* ???? The title prop is optional.
   * See https://storybook.js.org/docs/vue/configure/overview#configure-story-loading
   * to learn how to generate automatic titles
   */
  title: 'Design System/Navbar link',
  component: NavLink,
  subcomponents: { Link },
}

//???? We create a “template” of how args map to rendering
const Template = (args) => ({
  components: { NavLink, Link },
  setup() {
    //???? The args will now be passed down to the template
    return { args }
  },
  template: ' <NavLink href=args.href > Posts </NavLink>',
})

export const Default = Template.bind({})

Default.args = {
  /* ???? The args you need here will depend on your component */
  href: '/',
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦里的微风 2025-02-20 20:32:59

我相信您对出口默认的声明不好,应该是:

export default{components: {NavLink, Link}}

I belive you have a bad declaration on export default, it should be:

export default{components: {NavLink, Link}}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文