一个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