安裝
安裝bootstrap命令如下:
npm install bootstrap --save
安裝后可能報告如下錯誤:
npm WARN bootstrap@4.1.3 requires a peer of popper.js@^1.14.3 but none is installed. You must install peer dependencies yourself.
需要自行安裝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" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="external nofollow" >
這種方式太搞笑了吧,明明已經(jīng)在本地裝好了全套的bootstrap,偏偏CSS還要用網(wǎng)絡方式引入,又浪費流量,速度又慢,真是不知道想出這種方式的人是怎么想的。
補充:在electron中使用bootstrap時,雖然在引用bootstrap之前引用了jQuery,但是依然出現(xiàn)錯誤:
Uncaught error: bootstrap's javascript requires jquery
解決方法:不使用script標簽加載jQuery,而是使用下面的方法加載:
window.$ = window.jQuery = require('/path/to/jquery');以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持VeVb武林網(wǎng)。
新聞熱點
疑難解答