GithubHelp home page GithubHelp logo

Comments (3)

gsabater avatar gsabater commented on September 7, 2024 1

@steakscience Since the answers above didn't help me. I did it this way:

Import your component anyway at the top of your plugin or vue file

import Toast from '../components/toasts/Importing.vue'

And then pass it as the first param when calling

$toast = $nuxt.$toast.info(Toast)

Hope it helps

from vue-sonner.

joshuadempsey avatar joshuadempsey commented on September 7, 2024

If I understand your question correctly, Nuxt autoloads components so you can just follow the install guide and then in your App.vue...

`


<button @click="() => toast('My first toast')">Render a toast

<script lang="ts" setup> import { Toaster, toast } from 'vue-sonner' </script>`

This should work.

from vue-sonner.

Heunsig avatar Heunsig commented on September 7, 2024

If you have followed Sonner's setup instructions, you may have created a plugins/sonner.client.ts file to add the Toaster component globally. The word client in the filename signifies that the component is meant to be rendered exclusively on the client side. Yet, when the Toaster is used within a .vue SFC, the server attempts to render it as well, leading to an error since theToaster is configured to render on the client-side only.

To resolve this issue, enclose Toaster component within a <ClientOnly>. This ensures that the Toaster is rendered only on the client side.

Your code would then look like the following:

<!-- App.vue -->
<template>
  <!-- existing content -->
  <ClientOnly>
    <Toaster />
  </ClientOnly>
  <button @click="() => toast('My first toast')">
    Give me a toast
  </button>
</template>

from vue-sonner.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.