| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <div id="app">
- <p>
- <button class="push" v-on="click:push">push</button>
- <button class="pop" v-on="click:pop">pop</button>
- <button class="shift" v-on="click:shift">shift</button>
- <button class="unshift" v-on="click:unshift">unshift</button>
- <button class="splice" v-on="click:splice">splice</button>
- <button class="remove" v-on="click:remove">remove</button>
- <button class="set" v-on="click:set">set</button>
- <button class="sort" v-on="click:sort">sort</button>
- <button class="reverse" v-on="click:reverse">reverse</button>
- </p>
- <p>Total items: <span class="count" v-text="items.length"></span></p>
- <ul>
- <li class="item" v-repeat="items" v-ref="items">
- {{$index}} {{title}}
- </li>
- </ul>
- </div>
- <script src="../../../dist/vue.js"></script>
- <script>
- Vue.config({debug: true})
- var items = [
- { title: 'A'},
- { title: 'B'},
- { title: 'C'}
- ]
- var demo = new Vue({
- el: '#app',
- data: {
- items: items,
- push: function () {
- this.items.push({ title: getChar() })
- },
- pop: function () {
- this.items.pop()
- },
- shift: function () {
- this.items.shift()
- },
- unshift: function () {
- this.items.unshift({ title: getChar() })
- },
- splice: function () {
- this.items.splice(1, 1, { title: getChar() }, { title: getChar() })
- },
- set: function () {
- this.items.$set(getPos(), { title: getChar() })
- },
- remove: function () {
- this.items.$remove(getPos())
- },
- sort: function () {
- this.items.sort(function (a, b) {
- return a.title.charCodeAt(0) - b.title.charCodeAt(0)
- })
- },
- reverse: function () {
- this.items.reverse()
- }
- }
- })
- var getChar = (function () {
- var count = 0
- return function () {
- return (count++).toString()
- }
- })()
- function getPos () {
- return items.length - 1
- }
- </script>
|