这是一个常见的问题,但到目前为止还没有解决方案.我使用Laravel 10与Vite,安装Bootstrap与NPM和配置是确定使用引导CSS和引导图标,但我不能加载引导JS,这是必要的,使其工作模态,烤面包,弹出窗口,等.
vite.config.js:
export default defineConfig({
plugins: [
laravel({
input: ['resources/css/app.css', 'resources/js/app.js'],
refresh: true,
}),
],
resolve: {
alias: {
'~bootstrap': path.resolve(__dirname, "node_modules/bootstrap"),
'~bootstrap-icons': path.resolve(__dirname, "node_modules/bootstrap-icons/font")
}
}
});
字符串
resources/js/app.js
import * as bootstrap from 'bootstrap';
型
在主blade.php布局中删除文件(所有其他页面都扩展到该布局):
...
@vite(['resources/css/app.css', 'resources/js/app.js'])
...
型
以及发生错误的blade.php页面(未定义 Bootstrap )
...
<script>
window.onload = () => {
const toastLiveExample = document.querySelector("#liveToast")
const toast = new bootstrap.Toast(toastLiveExample)
toast.show()
}
</script>
...
型
1条答案
按热度按时间r8uurelv1#
在
app.js
文件中。您可以定义window.bootstrap = bootstrap
,以便可以在刀片中使用它。字符串