js用sort存在排序不正确漏洞

解决办法:
computed:{
sortItems:function(){
return this.items.sort(sortNumber)
}
}
function sortNumber(a,b){
return a-b
}


<html>
	<head>
		<meta charset="utf-8">
		<title>title>
		<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js">script>
	head>
	<body>
		<div id="app">
			<ul>
				<li v-for="item in sortItems">{{item}}li>
			ul>
		div>
		<script>
			var app=new Vue({
					el:'#app',
					data:{
						items:[23,53,43,13,6]
					},
					computed:{
						sortItems:function(){
							return this.items.sort(sortNumber)
						}
					}
			})
			function sortNumber(a,b){
					return a-b
			}
		script>
	body>
html>

你可能感兴趣的:(笔记)