需要自行安裝popper,命令如下:
npm install popper.js@^1.14.3 --save
頁面引入bootstrap
頁面引入bootstrap的css和js文件如下:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <link href="./node_modules/bootstrap/dist/css/bootstrap.min.css" rel="external nofollow" rel="stylesheet"/> </head> <body> Hello electron! <div> <button id="openFile" class="btn btn-success">Open File</button> <button id="sendMsg" class="btn btn-warning">Send Message (Open File)</button> </div> <script> window.$ = window.jQuery = require('./node_modules/jquery/dist/jquery.min.js'); require('./node_modules/bootstrap/dist/js/bootstrap.min.js'); </script>
注:網(wǎng)上有的例子中,引入bootstrap.min.css是用傳統(tǒng)方式引入,即:
<link rel="stylesheet" rel="external nofollow" >
這種方式太搞笑了吧,明明已經(jīng)在本地裝好了全套的bootstrap,偏偏CSS還要用網(wǎng)絡(luò)方式引入,又浪費流量,速度又慢,真是不知道想出這種方式的人是怎么想的。
補(bǔ)充:在electron中使用bootstrap時,雖然在引用bootstrap之前引用了jQuery,但是依然出現(xiàn)錯誤:
Uncaught error: bootstrap's javascript requires jquery
解決方法:不使用script標(biāo)簽加載jQuery,而是使用下面的方法加載:
window.$ = window.jQuery = require('/path/to/jquery');
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com