A
A
Alexander2018-11-26 18:44:00
Vue.js
Alexander, 2018-11-26 18:44:00

Why doesn't Vue work after removing an element?

Just started trying vue. There is a problem - I can not understand why it stops working after deleting and inserting a new element.
Those. suppose I somehow initialize vue like this:

var option = {
                            data: config.data,
                            methods: {
                                update: function (data) {
                                    for (var d in data) {
                                        this[d] = data[d];
                                    }
                                },
                            }
                        };
                    
                    
                    var $tmpl = $('#'+id+'_tmpl');
                        option.template = '#'+id+'_tmpl';
                        widget.vue = new Vue(option);
                        // монтируем элементы
                        widget.vue.$mount('#'+id);

Everything is fine. Everything is working. Exactly until the block containing '#'+id is replaced.
Those. let's say some other plugin changes part of the page. In doing so, it cuts out the block containing the element that vue is working with and replaces it with a new one.
After that I try to do widget.vue.$mount('#'+id); but nothing happens. I expect that the rendered template will be mounted into the new id that appears on the page. But no.
If I try to just repeat the whole procedure - i.e. I re-initialize the object after the replacement - it also, which surprisingly does not work.
I even tried doing .$destroy(); for widget.vue and then again widget.vue = new Vue(option); - but that doesn't work either :(

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question