javascript does not see new elements added by vuejs when I render a list.
I created a simple code, upon clicking on a list item, it prints its object in the console:
<head>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<style>
li {
font-size: 35px;
cursor: pointer;
padding-bottom: 5px;
}
.red {
color: red;
}
</style>
</head>
<body>
<div id="app">
<ul>
<li v-for="item in array">{{item}}</li>
</ul>
<button type="button" name="button" v-on:click="update">Update Array</button>
</div>
</body>
<!-- VueJS Script -->
<script type="text/javascript">
var app = new Vue({
el: '#app',
data: function () {
return {
array: [1, 2, 3, 4]
};
},
methods: {
update: function () {
app.array = [1, 2, 3, 4, 5, 6, 7, 8];
}
}
})
</script>
<!-- JQuery Script -->
<script type="text/javascript">
$("li").click(function () {
console.log(this);
});
</script>
</html>
It works fine only when the array is updated beforehand, when I add new elements to the array, JS cannot deal with new items. Why is that?