This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="app"> | |
<input type="number" v-model="add"> | |
<button @click="add_m">add</button> | |
<ul v-for="list in lists_c"> | |
<li>{{list}}</li> | |
</ul> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
new Vue({ | |
data(){ | |
return{ | |
lists:[32,6,8,19,37,3,19,37,5], | |
add:0 | |
} | |
}, | |
computed:{ | |
lists_c(){ | |
var vm = this, arr = vm.lists; | |
for(var i = 0; i < arr.length; i++){ | |
var lowest = i; | |
for(var j = i+1; j < arr.length; j++){ | |
if(arr[j] < arr[lowest]){ | |
lowest = j; | |
} | |
} | |
if(i !== lowest){ | |
var temp = arr[i]; | |
arr[i] = arr[lowest]; | |
arr[lowest] = temp; | |
} | |
} | |
return arr; | |
} | |
}, | |
methods:{ | |
add_m(){ | |
var vm = this | |
vm.lists.push(vm.add) | |
vm.add = 0 | |
}, | |
} | |
}).$mount('#app') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.min.js"></script> |
A Pen by Edward Lance Lorilla on CodePen.
0 Comments