ReferenceError: infors is not defined?

明明已经data(){}定义了infors这个数组,不知道为何F12控制台会报错。百度许久也未找到原因。

<template>

 <div>

子菜单一 <input  type="text">

 <ul>

 <li  v-for="(infor,index) in  infors" :key="index">

         -----{{infor.high}}

 </li>

 </ul>

 </div>

</template>

<script>

 import  axios  from  'axios'

 export  default {

 name:  'SubMenu1',

 data(){

 return{

 infors:[]

      }

    },

 mounted(){

     let  url='http://wthrcdn.etouch.cn/weather_mini?city=西安'

     axios.get(url).then(response=>{

       console.log(response.data);

       let  data=response.data;

       console.log(infors);

       this.infors= data.forecast;

       //console.log(infors);

     }).catch(error=>{

 console.log(error)

     })

    }

                  }

</script>

<style  scoped>

</style>
vue
最佳答案

console.log(infors); 应该改为console.log(this.infors);
data.data.ganmao 才对

闭包函数,变量的作用域。了解js的这两个概念这个问题就明白了。

2年前 评论
讨论数量: 3

this.infors

2年前 评论
Richard852555 (楼主) 2年前

console.log(infors); 应该改为console.log(this.infors);
data.data.ganmao 才对

闭包函数,变量的作用域。了解js的这两个概念这个问题就明白了。

2年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!