Skip to content
Advertisement

Why v-for won’t render any DOMs? ‘Property or method “data” is not defined on the instance but referenced during render.’

I would like to render several div containers depending on a returned API call from axios/vue. The axios call and callback work just fine, but vue won’t render any divs.

Since I am using Django, I already changed the delimiters from curly brackets (which is Django default as well).

Error message in console:

Property or method "data" is not defined on the instance but referenced during render. 
Make sure that this property is reactive, either in the data option, 
or for class-based components, by initializing the property.

Please find a minimal code snippet as follows (if you remove the JS part the html will show up):

Thank you in advance for your help!

var app = new Vue({
  delimiters: ['[[', ']]'],
  el: '.EUR_Quotes',
  data: {
    info: []
  },
  created() {
    axios
      .get("http://data.fixer.io/api/latest?access_key=XXXd&base=EUR")
      .then(response => {
        this.info = response.data.rates;
        console.log(response);
      });
  }
});
.EUR_Quotes {
  font-size: 30px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.13/vue.js"></script>
<html>
<head>
    
</head>
 <body>
    
    <div v-for="rates in info">
    <div class="EUR_Quotes">[[ data ]]
    </div>
    </div>
    
 </body>
  
<script src="https://unpkg.com/vue@2.5.13/dist/vue.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
  
</html>

Advertisement

Answer

You are confusing your data variable name, it should be info in your template, (not data) the actual data object is the container for all your vuejs app’s data.

Check the snippet, it works fine.

var app = new Vue({
  delimiters: ['[[', ']]'],
  el: '.EUR_Quotes',
  data: {
    info: []
  },
  created() {
    axios
      .get("http://data.fixer.io/api/latest?access_key=d&base=EUR")
      .then(response => {
        this.info = response.data.rates;
        console.log(response);
      });
  }
});
.EUR_Quotes {
  font-size: 30px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.13/vue.js"></script>
<html>
<head>
    
</head>
 <body>
    
    <div v-for="rates in info">
    <div class="EUR_Quotes">[[ info ]]
    </div>
    </div>
    
 </body>
  
<script src="https://unpkg.com/vue@2.5.13/dist/vue.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
  
</html>
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement