Property or method “xxxx“ is not defined on the instance but referenced during render. Vue报错

1. Property or method “xxxx” is not defined on the instance but referenced during render

有时候在写 vue 时突然就报这个错误了,Property or method “xxxx” is not defined on the instance but referenced during render,

报错错误理解:
属性或者方法 XXX 没有立即定义但是却在渲染时被引用。
报错信息已经十分明显了, XXX属性或方法没有定义,所以解决错误的办法是:定义这个属性或者方法

2. 定义属性或者方法

<script>
export default {
    
    
  data(){
    
    
    return{
    
    
      XXX: ''  // data中定义XXX属性
    }
  },
  methods: {
    
    
    XXX_() {
    
    
      // methods中定义某种方法
    }
  }
}
</script>

3. 定义了还是错误

如果定义了还是报这个错误,那么请一定检查定义的位置是不是正确的,博主偶尔也会出现这个问题, 但是是定义了的呀,这个时候就应该去看看,是不是位置写错了,很多时候我们会因为代码过多把方法写到 methods外面了,把属性写到 data外面了,所以请检查一下。

猜你喜欢

转载自blog.csdn.net/qq_41800366/article/details/107093282