Skip to content

The property hasn't been observed if no explicit set and the data() method provided. #1071

Closed
@TerenceZ

Description

@TerenceZ

I'm sorry I cannot provide a jsfiddle example (because I cannot find the cdn / rawgit for the latest dev code), instead here is the code I test on my machine with the latest dev vue (latest commit: eb95383).

<div id="app">
    <my-comp></my-comp>
</div>

<script>
new Vue({
    el: '#app',
    components: {
        'my-comp': {
            template: '<div>{{a}} - <input type="checkbox" v-model="a"></div>',
            replace: true,
            props: {
               a: {
                   default: false,
                   type: Boolean
               }
            },
            data() {
                return {
                    b: 123
                };
            }
        }
    }
});
</script>

In the above example, the v-model won't update the view's value.
In the above example, the v-model will update the model's value, but the model's value won't trigger the view to update because the model's value is not proxied.

The problem is that the initProp will set the default prop value on the vm, not an observable, and the _initData won't observe them also in some situation. Here is the cases:

  1. data() (also means no data options for instance) not supplied: because the _data is still the propsData, so the data will always be proxied even if it's no explicit set.
  2. data() supplied: the __data will be set to the optionsData, it will only proxy the optionsData, which means when the unproxied property value changes, nothing will be sync.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions