How to solve the error in VUE: Property or method “xxx“ is not defined on the instance but referenced during render

如何解决VUE中报错 [Vue warn]: Property or method “xxx” 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

Insert image description here

Vue.component(
    'component1', {
    
    
        props: {
    
    

        },
        template: ``,
        data:{
    
    
            a:"章三",
            b:"李四",
        },
        mounted() {
    
    

        },
        methods: {
    
    }
    }
)
Vue.component(
    'component2', {
    
    
        props: {
    
    

        },
        template: ``,
        data() {
    
    
            return {
    
    
                a:"章三",
                b:"李四",
            }
        },
        mounted() {
    
    },
        methods: {
    
    }
    }
)

When using a vue component, if the component is a function, data is used as a function name and the data object is used as the function return value. Because components may be used to create multiple instances. If data is still a pure object, all instances will share a reference to the same data object! By providing the data function, we can call the data function every time a new instance is created, thereby returning a new copy of the initial data data object.

Guess you like

Origin blog.csdn.net/weixin_45506717/article/details/124245280