一個JavaScript模塊要在帕格模板隨機字符串我想用random-string的JavaScript模塊。如何使用哈巴狗JS模板
首先,我通過NPM安裝這樣的:
npm install random-string
然後在帕格模板我用這個:
.site
.title
- var string = randomString({length: 20});
| #{string}
但是在編譯的文件,我得到這個錯誤:
randomString is not a function
如何在pug js temaplte中使用第三方javascript函數?
當然可以,但你需要把它作爲'pug'呈現參數,因爲你不能在''pug' require'。只需在外部環境中「需要」並通過它。 – MarcoL