Skip to content

zhongxingdou/vue-listen

Repository files navigation

vue-listen

Build Status NPM version

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)
})

About

Another vue watch but provide path info of changed object

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published