M
M
Mikhail Smirnov2020-11-02 11:45:58
Vue.js
Mikhail Smirnov, 2020-11-02 11:45:58

Why doesn't watch work?

The setParams method does not work watch section

What could be the problem?

props: {
            section:{ type: Object, default: false },
            showModal:{ type: Boolean, default: false }
        },

methods: {
setParams(param, itemId) {

                let index = this.section.filter_values[param].indexOf(itemId)

                if (index >= 0) {
                    this.section.filter_values[param].splice(index, 1);
                } else {
                    this.section.filter_values[param].push(itemId)
                }
            },
}


watch: {
            section (val, oldVal) {
                console.log('change section filter');
            }
        }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alex, 2020-11-02
@fortoster82

The observer does not look into the depths. To do this, you need to Register which specific property you want to monitor:
watch('section.filter_values.param')
Or set an additional parameter deep: true. Then it will recursively track all properties at any level of nesting.
Read more: https://vuejs.org/v2/api/#vm-watch

A
Alexey Yarkov, 2020-11-02
@yarkov Vue.js

deep: trueadd to watcher

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question