vue-listen
v1.3.7
Published
Listen vue data change and provide change path info to handler
Downloads
18
Maintainers
Readme
vue-listen
Install
npm install vue-listen --save
Usage
import Vue from 'vue'
import VueListen from 'vue-listen'
Vue.use(VueListen)
let vm = new Vue({
data: {
user: {
name: 'hal'
}
},
methods: {
nameWatcher (val, oldVal) {
console.info(oldVal + ' --> ' + val)
}
},
listen: {
user: {
handler: function (val, oldVal, path) {
console.info(val)
console.info(oldVal)
console.info(path.absolute)
console.info(path.relative)
},
deep: true
},
'user.name': 'nameWatcher'
}
})
vm.name = 'hal.zhong'
// output:
// hal
// hal.zhong
// user.name
// .name
// hal --> hal.zhong
vm.$listen('user.name', function (val, oldVal, path) {
conosle.info(val)
})