英文:
Javascript variable is not defined even though it is
问题
我正在运行一个Laravel项目,并在app.js
文件的顶部定义了一个名为wmDefaults
的对象,如下所示:
var wmDefaults = {
elemClass: 'waitMe',
effect: 'bounce',
text: '',
bg: 'rgba(255,255,255,0.7)',
color: '#000',
maxSize: '',
waitTime: -1,
textPos: 'vertical',
fontSize: '',
source: ''
};
app.js
文件已经包含在JavaScript外部资源列表中(参见下面的截图)。
然而,在尝试在console.log
中访问该变量后,我收到了错误消息:
VM2335:1 Uncaught ReferenceError: wmDefaults is not defined
at <anonymous>:1:13
我已经写JavaScript代码15年了,但我很尴尬地无法解决这个问题。非常感谢任何帮助。
英文:
I am running a Laravel project and defined an object wmDefaults
at the top of the app.js
file like this:
var wmDefaults = {
elemClass:'waitMe',
effect : 'bounce',
text : '',
bg : 'rgba(255,255,255,0.7)',
color : '#000',
maxSize : '',
waitTime : -1,
textPos : 'vertical',
fontSize : '',
source : ''
};
The app.js
file has been included in the list of javascript external resources (see screenshot below)
However, after trying to access the variable in console.log
, I get the error:
VM2335:1 Uncaught ReferenceError: wmDefaults is not defined
at <anonymous>:1:13
Been writing Javascript code for 15 years but I'm embarassed I can't figure this one out. Any help would be really appreciated.
答案1
得分: 1
Here is the translated content:
"我找到了解决方法。解决方案在这里:https://stackoverflow.com/questions/50484930/how-to-use-laravel-mix-define-global-javascript-function?rq=4
我需要在捆绑的 JavaScript 文件之外使用它,我必须将它附加到 window 对象上
window.wmDefaults = {
elemClass: 'waitMe',
effect: 'bounce',
text: '',
bg: 'rgba(255,255,255,0.7)',
color: '#000',
maxSize: '',
waitTime: -1,
textPos: 'vertical',
fontSize: '',
source: ''
};"
请告诉我下一步需要翻译的内容。
英文:
Okay so I figured this out. Solution here: https://stackoverflow.com/questions/50484930/how-to-use-laravel-mix-define-global-javascript-function?rq=4
I needed to use it outside of my bundled JavaScript files I had to attach it to the window object
window.wmDefaults = {
elemClass:'waitMe',
effect : 'bounce',
text : '',
bg : 'rgba(255,255,255,0.7)',
color : '#000',
maxSize : '',
waitTime : -1,
textPos : 'vertical',
fontSize : '',
source : ''
};
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论