Vuetify組件必須包裹在VApp元素內(nèi)。 默認(rèn)情況下,vue toastification容器附加到HTML body上(使其成為VApp容器的兄弟)。 要解決此問題,您可以在安裝vue toastification插件時添加以下代碼:
import Toast from "vue-toastification"; import type { PluginOptions } from "vue-toastification"; const ToastOptions: PluginOptions = { shareAppContext: true, container: () => document.getElementById("app")!, }; app.use(Toast, ToastOptions);
Container是toast應(yīng)該掛載的元素:HTMLElement或返回/解析為HTMLElement的函數(shù)。 Vuetify App元素應(yīng)該是一個id為#app的div
要訪問組件中可能使用的其他全局插件,例如i18n中的$t,您可能還希望訪問應(yīng)用程序上下文??梢酝ㄟ^添加shareAppContext選項(xiàng)來實(shí)現(xiàn)。 更多信息