Vue: 子组件在监听 父组件传递过来的Props数据时 输出 val和oldval数值竟然都是一样的!

Created on 25 Apr 2017  ·  1Comment  ·  Source: vuejs/vue

Version

2.2.6

Reproduction link

https://dajohnny.github.io/vue-demo/

Steps to reproduce

将my-tbale组件挂载到APP上,mytable组件下面有pagetemp和tabletemp组件,当my-table动态修改props给tabletemp 的 “tabledata.ajax”参数时,在子组件上面监听tabledata.ajax数值竟然发现 新的和旧的数值 是一样的!

Why tabletemp to watch 'tabledata.ajax' val and oldval is the same ?

以下是有问题的代码:
has question code :

    var  tabletemp = {
        template: '#tabletemp',
        props:['tabledata'],
         --------省略一些代码-------
        watch :{
            'tabledata.ajax': {
              handler: function (val, oldVal) {
                    console.log(val == oldVal);
                    console.log("why val and oldval is the same ??")
                    this.getDataList();
                },
              deep: true
            },
        }
    };

What is expected?

console.log(val == oldVal); ==> false

What is actually happening?

console.log(val == oldVal); ==> true


需求说明:假设在当前的tabledata.ajax数据里面新增shortname参数时,在监听tabledata,ajax假设有shortname参数改变后重置tabledata.ajax里面的其他参数。当时输出val和oldVal参数一样,无法判断是否shortname的参数是否改变!

Most helpful comment

如果是个对象被 mutate 而不是被整个替换valoldValue 当然是一样的。

另外,给 demo 要

  1. 有源码
  2. miminal

>All comments

如果是个对象被 mutate 而不是被整个替换valoldValue 当然是一样的。

另外,给 demo 要

  1. 有源码
  2. miminal
Was this page helpful?
0 / 5 - 0 ratings

Related issues

bdedardel picture bdedardel  ·  3Comments

hiendv picture hiendv  ·  3Comments

bfis picture bfis  ·  3Comments

seemsindie picture seemsindie  ·  3Comments

loki0609 picture loki0609  ·  3Comments