Is it possible to trigger a function upon a Vue data element change?
You can use a watch, like the following example:
var vm = new Vue({
el: '#demo',
data: {
firstName: 'Foo',
lastName: 'Bar',
fullName: 'Foo Bar'
},
watch: {
firstName: function (val) {
this.fullName = val + ' ' + this.lastName
},
lastName: function (val) {
this.fullName = this.firstName + ' ' + val
}
}
})
About your case, here is the example about how it could be implemented.
var vm = new Vue({
el: '#demo',
data: {
hash: 'Foo'
},
watch: {
hash: function (val) {
// when the hash prop changes, this function will be fired.
location.reload()
}
}
})
I hope I understood your question right.
I think this should work
var vm = new Vue({
el: '#root',
data: {
hash: null
},
watch: {
hash: function (val) {
functions_to_trigger_upon_an_element_change()
}
},
methods: {
functions_to_trigger_upon_an_element_change() {
// You code
}
}
})