trouble with v-for in Vue.js causing data not to show on page

Whenever I use console.log(e.data), I am able to retrieve values, but when attempting to display them using v-for, the data does not show up. Can someone please explain why this issue is occurring?

Below is the HTML code intended to display the values:

<div id="feed12">
  <div v-for="row in data">
    {{row.bussinessName}}
  </div>
</div>

Here is my Vue.js code:

<script type="text/javascript">
  new Vue({ 
    el: '#feed12' , 
    data: { 
      data: {}, 
    }, 
    mounted() { 
      navigator.geolocation.getCurrentPosition(success, error);
      function success(position) {
        var GEOCODING = 'https://maps.googleapis.com/maps/api/geocode/json?latlng=' + position.coords.latitude + '%2C' + position.coords.longitude + '&language=en';
        $.getJSON(GEOCODING).done(function(location) {
        $('#country').html(location.results[0].address_components[5].long_name);
          $('#state').html(location.results[0].address_components[4].long_name);
          $('#city').html(location.results[0].address_components[2].long_name);
          $('#address').html(location.results[0].formatted_address);
          $('#latitude').html(position.coords.latitude);
          $('#longitude').html(position.coords.longitude);
        })

        var lat = position.coords.latitude;
        $.ajax({
          url: 'https://n2s.herokuapp.com/api/post/filter/',
          data: {
            lat: position.coords.latitude,
            lon: position.coords.longitude,
          },
          type: "POST",
          dataType: 'json',
          success: function (e) { 
            if (e.status == 1) { 
              self.data = e.data; 
              console.log(e.data) 
            }
          }
        });
        console.log(lat);
      }

      function error(err) {
        console.log(err)
      }
    }
  })
</script>

Answer №1

It seems that you have overlooked assigning your self to this. Simply update your code from:

mounted() { 
  navigator.geolocation.getCurrentPosition(success, error);

to

mounted() { 
  var self = this;
  navigator.geolocation.getCurrentPosition(success, error);

If there's an issue in your code, debugging should catch it. Vue-Devtools can help identify conflicts within your Vue code using the console. I personally prefer the chrome addon for this purpose. Remember to include Vue.config.devtools = true, or opt for the dev build of Vue.js instead of the minified version.

Check out https://github.com/vuejs/vue-devtools for more information.

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

Is there a way to modify the variable in order to switch the font of the heading every second using CSS and JavaScript?

I'm trying to create a heading that changes fonts every second, but I'm having trouble changing the variable to set it to another font. Check out my code here. Despite watching tutorials, everything seemed too confusing. var root = document.q ...

Switch the design and save it in the browser's cache

Exploring the possibility of having two themes, "dark" and "light," that toggle when a checkbox is clicked. To implement the theme change, I used the following JavaScript code: document.documentElement.setAttribute('data-theme', 'dark&apos ...

Transferring the chosen dropdown value to the following page

I am attempting to transfer the currently selected value from a dropdown to the next page using an HTTP request, so that the selected value is included in the URL of the subsequent page. The form dropdown element appears as follows: <form name="sortby ...

Identifying the opening of a folder or file in an electron/node application

Is there a way to retrieve the name of a folder or file when they are opened? I have tried using fs.watch event, but it only seems to work when renaming, adding, or removing files/folders within the specified directory. For instance: //This code only de ...

Send a PUT request using Ajax

I am a beginner when it comes to Ajax requests and I have crafted the code shared in this Pastie. On line 107, my $.PUT function is causing an error in Firebug stating that $.PUT is not a recognized function. I acknowledge that there are issues with my aja ...

The delimiting slash is absent between hosts and options

Hello there (I hope my English is not too bad)! Currently, I'm attempting to set up a basic database using MongoDB Atlas (the online alternative), but I am facing an issue at the very first step: connecting! Every time I try, I encounter the same err ...

Steps to redirect to an external page after successful login, even if it's not hosted on the server

I have developed an HTML5 app on my phone. Once the correct username and password are entered, the app is supposed to connect to an external server, authenticate the credentials in the database, and then redirect me to another page (Home Page) within the a ...

Protect your Laravel and Vue SPA from CSRF attacks by securely storing the JWT token in an HttpOnly cookie

Frontend uses Vue.js for the single page application (SPA). The backend is built on Laravel framework. The frontend and backend are decoupled, communicating with each other through xhr requests. Initially, I stored the JWT token in local storage for aut ...

Display video exclusively on desktop using Next.js: useEffect is unable to update a React state on a component that is unmounted

I am facing an issue with my Next.js website where I want to render a video only on desktop and not on mobile. To achieve this, I created a custom React hook to track the window size using the isDesktop state variable. While everything seems to be working ...

Display elements on hover of thumbnails using CSS

I'm struggling with the logic of displaying images when hovering over corresponding thumbnails using only CSS. If necessary, I can do it in JavaScript. Here's my latest attempt. <div id='img-container' class='grd12'> ...

A stationary webpage nested within a lively pathway on NuxtJS

I have a Nuxt app with a list of cars available at: /cars. You can select a specific car at /cars/:id. I would like to have a toolbar that routes to different views such as: /cars/:id/routes, /cars/:id/drivers, etc. Within the /cars/:id page, I have creat ...

Developing distinct state values for assigned objects

I developed a star rating component using Material UI components that is based on a mapped object. However, I am facing an issue where all the star ratings show the same value when clicked. How can I ensure that each star section displays its own value bas ...

"Utilizing Vue.js for Managing Foreign Keys in Database Entries

I am currently utilizing input in Vue.js. The structure of this input is as follows: induk_id:'', nama_barang:'', qtt:'', satuan:'', har ...

A guide on extracting the value of a key from an object in angularjs

I stored the data in an object like this: $scope.modelName = { name: {} }; The data was saved as {"APPLE":true,"ORANGE":true}. I am attempting to retrieve only the keys and save them in another object using a for loop. However, I'm having troubl ...

When the enter key is pressed, shift the text to a different input field

I am facing a complex requirement How can I detect the pressing of the ENTER key within a text box with the following conditions: If the cursor is at the end of a sentence, it should create a new text box on the next row. If the cursor is in the middle ...

D3 mouse interaction differs from touch events, such as clicking -> supported touch event

Searching for examples of using D3 on a mobile device with touch events instead of mouse events has been challenging. I am unable to find clear information on what touch event corresponds to each mouse event, such as click or dblclick. This has hindered my ...

Unable to retrieve location data within the function

I've been grappling with this issue for quite some time now. I have three functions that are all functioning properly individually. However, I'm facing a challenge of retrieving the value from getUserCoordinates() and passing it to fetchCurrentTe ...

The challenge of optimizing Angular websites for SEO while also addressing page reload issues

I am struggling to create SEO-friendly URLs in my Node server backend. I want URLs like the following: http://localhost:3003/my-new-mobile //product http://localhost:3003/my-new-category //category http://localhost:3003/my-first-blog-post // blog post I ...

Resultant vector

Having trouble calculating the resultant of 3 vectors. Every time I input a number, it returns NaN. Can someone shed some light on this? var vector1 = document.getElementById("f1"); var vector2 = document.getElementById("f2"); var vecto ...

When using jQuery, remember to encode square brackets in order to target specific

Imagine an input element <input id="meta[152][value]" type="text" /> In this case, the input field is created on-the-fly. I must choose that particular field. That's why I used, alert($('#meta[152][value]').val()); However, it appe ...