javascript - Vue.js - Inconsistencies between model and rendered content -


i have following minimum example:

<html>   <head>     <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.1/jquery.min.js"></script>     <script src="https://unpkg.com/vue/dist/vue.js"></script>    </head>   <body>     <div id="app">     <ol>         <li v-for="series in currentseries" v-bind:data-id="series.id">         id <% series.id %>         <a href="javascript:;" class="removeseries">x</a>         </li>       </ol>     </div>   </body>    <script>     vm = new vue({     el: '#app',     delimiters: ["<%", "%>"],     data: {         currentseries: [{id: "1"}, {id: "2"}, {id: "3"}]     },      methods: {         removeseries: function(id) {         this.currentseries = this.currentseries.filter(function(element) {             return element.id != id;         });         }     }     });     $(function() {        $(document).on("click", ".removeseries", function() {        var id = $(this).parent().data("id");        console.log(id);        vm.removeseries(id);        });    });   </script> </html> 

i have list of series in variable currentseries. create list of these, adding -tag each item remove list.

if click on first 'x', first element removed list , id 1 shown in console. then, if again click on first element, should remove second element (which first one). however, output id still 1, i.e. data-id not updated of node during rendering. what's problem here , how improve on this?

you mixing jquery vue , both conceptually different. here jquery entirely unnecessary because can use vues built in click event:

// call remove series on click , remove element given id <a href="#" @click="removeseries(series.id)">x</a> 

now, call removeseries given id , can update underlying model data want.

here's jsfiddle:

https://jsfiddle.net/vyra5nzc/

just note on delimiters, vue accepts @{{data}} delimiter if using double mustache in other templating engine such laravels blade.


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -