layui 拓展自定义模块 csrf_token报此错误
查找原因发现,jquery 已经引入进来,但是 csrf_token 依赖 jQuery
解决办法:
在 csrf_token 文件最上方加上
window.jQuery= layui.$;
即可。
示例:
layui.define(function (exports) {
window.jQuery= layui.$;
var $ = layui.$;
// get cookie using jQuery
function getCookie(name) {
let cookieValue = null;
if (document.cookie && document.cookie !== '') {
let cookies = document.cookie.split(';');
for (let i = 0; i < cookies.length; i++) {
let cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) === (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length +