Express js 渲染 pug|ejs 文件抛出 Jquery 错误
Express js render pug|ejs file throws Jquery error
我在使用 ExpressJs 渲染时遇到问题 Jquery。
我的app.js(主文件)是
restapi=require('express')();
const pug = require('pug');
restapi.use(express.static(__dirname+"/public"));
restapi.set('views', __dirname+'/views');
restapi.set('view engine','pug');
restapi.get("/view/:datalog?",(req, res)=>{
var datalog=req.params.datalog;
res.render("index",{title:"Hey",rows:"hello"});
})
我的 index.pug 文件(我也一直在使用 EJS)是
html
head
title= title
script(src='/js/jquery-3.1.1.min.js')
script.
window.$ = window.jQuery = module.export;
$().ready(function(){console.log("READY")});
(alert("HELOOOOOOOOOOOOOOOOO"))
body
rows
它抛出一个找不到 jquery 模块的错误
如果我删除 window.$ = window.jQuery = module.export
(我什至尝试使用 = require("jquery"
)而不是模块导出),简单的 javascript 会向我显示警报。
我什至尝试过 link jquery 脚本到 cdn 存储库。它总是让我出错。
我什至尝试过将所有文件移动到没有 public/static 分配的根文件夹。
似乎没有任何效果...
我错过了什么?!
您检查 /js/jquery-3.1.1.min.js
是您的 jQuery 文件的有效路径吗?
然后只需使用下面的简洁语法:
html
head
title= title
script(src='/js/jquery-3.1.1.min.js')
script.
jQuery(function ($) {
alert('ready');
});
body
rows
我在使用 ExpressJs 渲染时遇到问题 Jquery。
我的app.js(主文件)是
restapi=require('express')();
const pug = require('pug');
restapi.use(express.static(__dirname+"/public"));
restapi.set('views', __dirname+'/views');
restapi.set('view engine','pug');
restapi.get("/view/:datalog?",(req, res)=>{
var datalog=req.params.datalog;
res.render("index",{title:"Hey",rows:"hello"});
})
我的 index.pug 文件(我也一直在使用 EJS)是
html
head
title= title
script(src='/js/jquery-3.1.1.min.js')
script.
window.$ = window.jQuery = module.export;
$().ready(function(){console.log("READY")});
(alert("HELOOOOOOOOOOOOOOOOO"))
body
rows
它抛出一个找不到 jquery 模块的错误
如果我删除 window.$ = window.jQuery = module.export
(我什至尝试使用 = require("jquery"
)而不是模块导出),简单的 javascript 会向我显示警报。
我什至尝试过 link jquery 脚本到 cdn 存储库。它总是让我出错。
我什至尝试过将所有文件移动到没有 public/static 分配的根文件夹。
似乎没有任何效果... 我错过了什么?!
您检查 /js/jquery-3.1.1.min.js
是您的 jQuery 文件的有效路径吗?
然后只需使用下面的简洁语法:
html
head
title= title
script(src='/js/jquery-3.1.1.min.js')
script.
jQuery(function ($) {
alert('ready');
});
body
rows