`How can data be transferred from a Vue.js file to a different HTML file?`

In the widget, the value of the "symbol" attribute needs to be dynamic based on the selected currency pair from the list. In the Vue.js file, the value of the currency pair is stored in the "symbol" variable. I am trying to pass this variable value from the Vue file to regular HTML so that it can be used later. The following are code snippets from both the Vue.js and HTML files:

    <select v-model="currSymbol" @change="event => socket.emit('symbol:change', {symbol: currSymbol, interval: currInterval})">
    <option v-for="pair in pairs">
      {{ pair.symbol }}
    </option>

HTML file:

 <div id="app">
    <div class="tradingview-widget-container">
      <div class="tradingview-widget-container__widget"></div>
    </div>
  </div>

  <script type="text/javascript" src="https://s3.tradingview.com/tv.js"></script>


  <script type="text/javascript">
    new TradingView.widget(
    {
      "width": 1000,
      "symbol": "{{ symbol }}",
      "interval": "D",
      "timezone": "Etc/UTC",
      "theme": "light",
      "style": "1",
      "locale": "en",
      "toolbar_bg": "#f1f3f6",
      "enable_publishing": false,
      "allow_symbol_change": true,
      "container_id": "tradingview_02e7f"
    }
    );
  </script>

I am facing challenges in transferring the value between these files.

Answer №1

If you wish to enhance your project, introducing two new components is a great idea.

One such component is the wrapper component. Here's an example:

<template>
<div>
   <currency-chooser @choose='updateCurrency'/>
   <stock-chart :currencyType='currency'/>
</div>
</template>
<script>
...
data() {
   return {
     currency: null,
   }
},
methods: {
  updateCurrency(e) {
     this.currency = e
  },
},
...
</script>

The stock-chart component looks like this:

<template>
    <div class="tradingview-widget-container">
      <div class="tradingview-widget-container__widget"></div>
    </div>
 </template>

<script>
...
props: {
   currencyType: {
     
   }
},
watch: {
  currencyType: {
     handler(e) {
        this.initializeStockChart()
     }
  }
},
methods:{
   initializeStockChart() {
     new TradingView.widget(
    {
      "width": 1000,
      "symbol": this.currencyType,
      "interval": "D",
      "timezone": "Etc/UTC",
      "theme": "light",
      "style": "1",
      "locale": "en",
      "toolbar_bg": "#f1f3f6",
      "enable_publishing": false,
      "allow_symbol_change": true,
      "container_id": "tradingview_02e7f"
    }
    );
   },
}
    
  </script>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having trouble typing computed values in Vue Composition API with TypeScript?

I'm attempting to obtain a computed value using the composition API in vue, and here is the code I am working with: setup() { const store = useStore(); const spaUrls = inject<SpaUrls>('spaUrls'); const azureAd = inject<AzureAd ...

JavaScript/jquery loop with an increasing index each iteration

I am currently working with a JSON file that contains paths to various images. I want to regularly add more image paths to this file and display them on an HTML page. However, I am encountering an issue when using the $.each method - the index remains the ...

Troubleshooting Vercel and Express DELETE request cross-origin resource sharing problem

Currently, I am in the process of developing an API using Vercel and ExpressJS. The GET and POST endpoints are functioning properly, however, I encountered an issue with the DELETE endpoint. When attempting to access the endpoint from my client-side JavaSc ...

Unable to navigate beyond the boundaries of an app

I am currently facing an issue with my authentication service where it redirects to the identity server in case of certain errors. I attempted to achieve this using window.location.href = environment.authCodeFlowIssuer;, however, an error occurred: Ref ...

Guide on choosing a date from a datepicker that is always 21 days ahead of the current date using Selenium and Java

Here is the code snippet I am working with: SimpleDateFormat df = new SimpleDateFormat("dd/MM/YYYY"); Date dt = new Date(); Calendar cl = Calendar.getInstance(); cl.setTime(dt); cl.add(Calendar.DAY_OF_YEAR, 21); dt=cl.getTime(); ...

Checking for the accuracy of the provided full name

There is a specific task at hand: The field labeled “First Name Last Name” must only contain 2 words, with each word being between 3 and 30 characters in length. Additionally, there should be only one space between the first and last name. The issue t ...

The feature of automatically selecting all text input content upon focus is not functioning properly in Microsoft Edge

I've encountered a specific issue with Microsoft Edge when trying to select all the text in an input field. My approach involves using Angular's ng-focus to trigger a function in the controller that selects the text in the field. function select ...

Is there a way to create a curve that stays below the text and does not intersect with it?

I am attempting to center a text on a quadratic curve or line, as shown in the image below: https://i.stack.imgur.com/XH6Fw.png My current approach using ctx.fillText results in the text overlapping the curve. https://i.stack.imgur.com/ddwue.png Is ther ...

Tips for configuring CakePHP to trigger the second submit button when the enter key is pressed

My form includes two submit buttons: "cancel" and "find." While both buttons work correctly when clicked, pressing the enter key always triggers the submission of "cancel." I don't want to change the button order in the form. To address this issue, I ...

JQuery toggle() function malfunctioning on 1.9.1 version

Experimented with using the Jquery toggle event in the code snippet below: $("button:eq(2)").toggle(function(){ $(this).attr("style","background:red");}, function(){ ...

Developing UIs in React that change dynamically according to the radio button chosen

Problem Statement I am currently developing a web application feature that computes the heat insulation factor for a specific area. You can view the live demonstration on Codesandbox <a href="https://codesandbox.io/p/github/cloudmako09/btu-calc/main?im ...

What are some effective methods for optimizing GLSL/C code in Three.JS when using PerObject-Blur?

UPDATE 2 I have successfully integrated custom attributes using THREE.js. Each pass in the vertex shader is now aligned with the position attribute, resulting in an efficient solution with minimal code. An example will be added later UPDATE 1 This me ...

Unable to upload to Storage due to an error in the AWSS3Provider, which is throwing a TypeError: Cannot read property 'byteLength' of undefined

React Native (Expo) AWS Amplify Auth (Authentication) AWS Amplify Predictions (Recognition) Encountering the error message Cannot read property 'byteLength' of undefined when trying to upload media files to an S3 bucket using AWS Amplify Storage ...

Issue with refreshing Angular2 page causing it to not load

Encountering an issue here. When clicking on the anchor tag in my index <a href="/month/1">Month</a> the app fails to load, but when clicking on the anchor tag in my component <a routerLink="/month/1"> Month</a> the app success ...

ERROR occurred in the renderer.js file due to an unexpected punctuation token «(»

Version: webpack 2.3.3 Hello, I am currently working on developing my first Electron app using Vuejs. The process has been smooth so far until I encountered an issue during the packaging phase. Running npm run dev works perfectly fine, but when I execut ...

Monitor modifications to documents and their respective sub-collections in Firebase Cloud Functions

Is it possible to run a function when there is a change in either a document within the parent collection or a document within one of its subcollections? I have tried using the code provided in the Firebase documentation, but it only triggers when a docume ...

Having trouble getting Visual Studio Code IntelliSense to work properly with NodeJS?

I've been using VS Code for my NodeJS projects, but I'm having trouble with IntelliSense not working for the classes and files I'm writing. I tried a solution from here, but it didn't work for me. Can anyone help me fix this issue? VS ...

Encountering the issue of "TypeError: Cannot read property 'file' of undefined" when trying to upload a video with Multer

The objective is to select a video file from the desktop and upload it to the platform. The uploaded video file will then be automatically posted to a specified Youtube channel using GCD. An error message I encountered is:"react-dom.development.js:40 ...

What is the best way to utilize the ajax factory method in order to establish a $scoped variable?

One issue I frequently encounter in my controllers is a repetitive piece of code: // Get first product from list Product.get_details( id ) .success(function ( data ) { // Setup product details $scope.active_product = data; }); To avoid this ...

Google Maps autocomplete feature is causing the input to update only after clicking in ng-model

After fetching a Google Maps place ID from a REST API, I utilize the Google Maps API to retrieve the place object in this manner: var geocoder = new google.maps.Geocoder; geocoder.geocode({ 'placeId': data.city }, fun ...