This time I will bring you the method of operating array data in vue.js. What are the precautions for operating array data in vue.js? Here are the actual cases, let’s take a look.
1. By default, Vue.js does not support adding repeated data to an array. This can be achieved using track-by="$index".
JavaScriptcode
<script type="text/javascript" src="../js/vue-1.0.21.js"></script> <script type="text/javascript"> window.onload = function() { vm = new Vue({ el: '#app', data: { arrMsg: ['apple', 'orage', 'pear'] }, methods: { add: function() { this.arrMsg.push('tamota'); } } }); } </script>
<p id="app"> <!--显示数据--> <ul> <li v-for="value in arrMsg" > {{value}} </li> </ul> <button type="button" @click="add">增加数据</button> </p>
<script type="text/javascript" src="../js/vue-1.0.21.js"></script> <script type="text/javascript"> window.onload = function() { vm = new Vue({ el: '#app', data: { arrMsg: ['apple', 'orage', 'pear'] }, methods: { add: function() { this.arrMsg.push('tamota'); } } }); } </script>
<p id="app" class="container"> <!--显示数据--> <ul> <li v-for="value in arrMsg" track-by="$index" > {{value}} </li> </ul> <button type="button" @click="add" >增加数据</button> </p>
LoopError reporting Vue.js does not support adding repeated data to arrays by default. This can be achieved using track-by="$index"
. I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
The above is the detailed content of vue.js method of operating array data. For more information, please follow other related articles on the PHP Chinese website!