Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
142
rated 0 times [  147] [ 5]  / answers: 1 / hits: 24073  / 8 Years ago, wed, october 5, 2016, 12:00:00

I'm trying to build a simple app in vue and I'm getting an error. My onScroll function behaves as expected, but my sayHello function returns an error when I click my button component




Property or method sayHello is not defined on the instance but
referenced during render. Make sure to declare reactive data
properties in the data option. (found in component )




Vue.component('test-item', {
template: '<div><button v-on:click=sayHello()>Hello</button></div>'
});

var app = new Vue({
el: '#app',
data: {
header: {
brightness: 100
}
},
methods: {
sayHello: function() {
console.log('Hello');
},
onScroll: function () {
this.header.brightness = (100 - this.$el.scrollTop / 8);
}
}
});


I feel like the answer is really obvious but I've tried searching and haven't come up with anything. Any help would be appreciated.



Thanks.


More From » vue.js

 Answers
34

But for a few specific circumstances (mainly props) each component is completely isolated from each other. Separate data, variables, functions, etc. This includes their methods.



Thus, test-item has no sayHello method.


[#60503] Sunday, October 2, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
anikas

Total Points: 258
Total Questions: 102
Total Answers: 95

Location: Monaco
Member since Sun, Jan 16, 2022
2 Years ago
;