vue+lowdb+express
2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>
搭建流程: 1.安裝Node.js;
2.安裝npm;
3.安裝Express;
搭建流程
npm install -g express安裝 express 生成器
npm install -g express-generator查看是否安裝成功,隨便輸?shù)囊粋€(gè)命令
express --help創(chuàng)建項(xiàng)目文件夾
express -e ejs server一、將express 的ejs改成html模版引擎
在server文件夾下的app.js里面修改 app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'html'); app.engine('.html',require('ejs').__express);然后將views里面的.ejs文件改變成 .html文件
二。運(yùn)行時(shí)報(bào)錯(cuò):node 報(bào)錯(cuò)Can't set headers after they are sent.
https://blog.csdn.net/u014182411/article/details/78315679
原因:
router.post('/getPage', function (req, res, res) {console.log(req)if (err) {res.send(err)}let str = db.get('pages')if (str === '') {res.send({code: '202',result: '沒(méi)有數(shù)據(jù),請(qǐng)?zhí)砑?#39;})} else {res.send({code: '200',result: str})} })這個(gè)error走了下面的又走了,就會(huì)出現(xiàn)問(wèn)題,解決辦法 監(jiān)測(cè)到error 時(shí) return 一下
router.post('/getPage', function (req, res, error) {if (error) {return res.send(error)}let str = db.get('pages')if (str === '') {res.send({code: '202',result: '沒(méi)有數(shù)據(jù),請(qǐng)?zhí)砑?#39;})} else {res.send({code: '200',result: str})} })遇到問(wèn)題: 1、我想引入iconfont圖標(biāo) 在views同級(jí)剪了一個(gè)文件夾,名字是iconfont 將下載的文件放在里面,在views下的html里引入報(bào)錯(cuò):
*because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.*解決辦法: 下面是express解析靜態(tài)資源的設(shè)置,所以我們只有把靜態(tài)資源放在public 文件夾目錄下才能解析到
app.use(express.static(path.join(__dirname, 'public')));html文件引入的方法 <link rel="stylesheet" type="text/css" href="./iconfont/iconfont.css">上面的都是依據(jù)我自己的項(xiàng)目所寫(xiě)的
轉(zhuǎn)載于:https://my.oschina.net/u/3608045/blog/2990645
總結(jié)
以上是生活随笔為你收集整理的vue+lowdb+express的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: springboot整合图像数据库Neo
- 下一篇: vuex重置所有state(可定制)