[英]How do you gain access to global variables and functions from Javascript scripts imported from index.html and use them in a component?
[英]How to use global variables in Ember app, specifically in index.html?
我想使用传入的命令行变量直接修改Ember应用程序的index.html。因此,我可以在我的environment.js文件中的“ ENV”下设置它们,然后在一些.js文件中访问它们通过导入ENV。 但是,在我的index.html文件中,即使“ rootURL”变量出现了,这些变量也没有出现。 例如,如果我在ENV中设置rootURL: "/blah"
和var1: "/blah2"
,则如果我有类似a href={{rootURL}}
和a href = {{var1}}
,则第一个链接有效,而第二个无效。
因此,我假设{{rootURL}}不是直接来自ENV变量,但是我找不到它来自哪里。 我试图对'app.js'中的变量做类似的事情,但是我对这行感到困惑: import config from './config/environment';
这到底导入了什么? 我在environment.js中找不到任何名为“ config”的东西。 是否可以在该文件(app.js)中设置全局变量?
我正在使用ember-cli-inline-content
在索引中使用变量,因此可以根据环境(生产或开发)来更改某些网址,例如:
<link rel="stylesheet" href="{{content-for 'ASSETS_BASE_URL'}}/xxx/yyy/assets/vendor.css">
在我的ember-cli-build.js
文件中:
if (app.env === 'development') {
app.options.inlineContent = {
ASSETS_BASE_URL: {
content: 'http://lvh.me:8080'
}
};
}
if (app.env === 'production') {
app.options.inlineContent = {
ASSETS_BASE_URL: {
content: 'https://assets.mydomain.com'
}
};
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.