I am unsure if this is the right place to ask this question, but I am currently using the tradingview
library. While it is working for me, it is not functioning the way I intend it to.
As per the documentation, I have placed my code in the index.html
file in Vue, under a script tag, and my tradingview
works. However, I am trying to move this code under the mounted
hook, and I am encountering the following error:
Error in mounted hook: "ReferenceError: TradingView is not defined"
Below is an example of the code in my index.html
file that is working:
<script type="text/javascript" src="/charting_library/charting_library.min.js"></script>
<script type="text/javascript" src="https://d33t3vvu2t2yu5.cloudfront.net/tv.js"></script>
<script>
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
TradingView.onready(function() {
var widget = new TradingView.widget({
symbol: 'Bitfinex:ETHUSD',
interval: '30',
theme: 'Dark',
style: '1',
container_id: "tv_chart_container",
library_path: "/charting_library/",
locale: getParameterByName('lang') || "en",
width: '100%',
height: '600px',
debug: false,
preset: "mobile"
});
})
And here is the code of mounted in my vue file:
mounted () {
TradingView.onready(function() {
new TradingView.widget({
symbol: 'Bitfinex:ETHUSD',
interval: '30',
theme: 'Dark',
style: '1',
container_id: "tv_chart_container",
library_path: "/charting_library/",
locale: this.getParameterByName('lang') || "en",
width: '100%',
height: '600px',
debug: false,
preset: 'mobile'
})
})
}
Can anyone provide insight into why TradingView
is not defined in this context?