12345678910111213141516171819202122232425 |
- function watch(
- this: {
- data: Record<string, string>
- } & any,
- key: string,
- callback: (val: any) => void,
- ) {
- console.log(this, '555')
- // 先执行一次watch
- callback.call(this, this.data[key])
- let that = this
- let tmpData = this.data[key]
- Object.defineProperty(this.data, key, {
- set: function (value) {
- tmpData = value
- callback.call(that, value)
- console.log('item change', value, key)
- },
- get: function () {
- return tmpData
- },
- })
- }
- export default watch
|