我试图使用Toastify-js,这是用于吐司类型消息的库,使用NPM安装。
在文档中,运行安装COMAND后,它说:
-Import toastify-js进入模块以开始使用它。
从“ toastify-js”
导入吐司
但是当我在代码中插入该导入行时,我会收到此消息:
unturew typeError:无法解析模块指定符“ toastify-js”。
相对引用必须以“/”,“ ./”或“ ../” ../ p>开始
我认为我可能没有理解的东西...我应该把那条线放在哪里?或我在做错什么。文档是否假设使用我不知道的NPM安装的库,也许?
Im trying to use Toastify-js, a library for toast type messages, installing it using npm.
In the documentation, after running the installing comand it says:
-Import toastify-js into your module to start using it.
import Toastify from 'toastify-js'
but when i inlude that import line in my code i get this message:
Uncaught TypeError: Failed to resolve module specifier "toastify-js".
Relative references must start with either "/", "./", or "../".
I think theres probably something im not understanding... where should i put that line? or what im doing wrong. Is the documentation assuming something about using npm-installed libraries that I don't know about, maybe?
发布评论
评论(1)
我知道回答有点晚了,但我自己现在就发现了。为了通过在Laravel Blade文件中通过NPM安装toastify-js,首先必须编译一个由导入烤面包的JavaScript文件。
首先,安装toastify-js。
并在JavaScript文件中导入烤面包和CSS。对我来说,我只是使用默认的app.js
resources/js/app.js
,然后我们必须在vite.config.js中编译“ app.js”文件。
vite.config.js
汇编后,我们可以通过刀片文件中的Vite Blade指令链接App.js文件。您可以将指令放在关闭的主体标签之前或您想要的任何地方。
然后,刀片文件中的任何地方都可以写脚本以显示烤面包。
还要确保脚本标签具有“模块”的类型。否则,烤面包不会出现。
希望您可以按照这些步骤以相同的方式显示烤面包。请告诉我,如果我有任何我应该知道的要修复或改善此方法的东西。
另外,要知道如何更好地自定义吐司,请确保阅读Toastify-JS文档。
I know it is a bit late for answering but I just found out about it myself right now. In order to use toastify-js by installing through npm in Laravel blade files firstly we must compile a JavaScript file which consists of importing Toastify.
Firstly of course, install the toastify-js.
And in a JavaScript file import the Toastify and CSS of it. For me, I just went with the default app.js
resources/js/app.js
And after that we must compile the "app.js" file in vite.config.js.
vite.config.js
After the compilation, we can just link the app.js file through the vite blade directive in our blade file. You can just put the directive before the closing body tag or anywhere you like if you want to.
And then anywhere in your blade files you can just write the script to show the toast.
And also makes sure that the script tag has the type of "module". Or else, the toast will not show up.
I hope you can show toast the same way by following those steps. Please let me know if I have anything that I should know to fix or to improve this method.
Also, in order to know how to customize your toast better, make sure to read the toastify-js docs.
https://github.com/apvarun/toastify-js/blob/master/README.md