<!DOCTYPE html>
<html>
<head>
<meta charset=
"utf-8"
>
<title>Vue测试2</title>
<script type=
"text/javascript"
src=
"js/vue.min.js"
></script>
<style type=
"text/css"
>
*{
padding: 0;
margin: 0;
font-size: 14px;
font-family:
"微软雅黑"
;
}
#box{
width: 500px;
height: auto;
border: 1px solid #ccc;
margin: 50px auto;
padding: 10px;
}
.search{
width: 480px;
height: 100px;
text-align: center;
}
.searchBox{
width: 230px;
height: 40px;
outline: none;
text-indent: 10px;
margin-right: 20px;
}
.btn{
width: 100px;
height: 50px;
cursor: pointer;
font-size: 18px;
}
.goodsheet{
width: 500px;
height: auto;
border: 1px solid #eee;
}
.goodsheet tr td,
.goodsheet tr th{
width: 33%;
border: 1px solid #eee;
padding: 5px 10px;
text-align: left;
}
.goodsheet tr th span{
background: #ff9900;
padding: 0 6px;
color: #fff;
cursor: pointer;
}
</style>
</head>
<body>
<p id=
"box"
>
<p
class
=
"search"
>
<input type=
"text"
class
=
"searchBox"
v-model=
"searchVal"
>
<button
class
=
"btn"
>搜 索</button>
</p>
<table
class
=
"goodsheet"
>
<tr>
<th>商品名</th>
<th>单价
<span @click=
"orderFn('price', false)"
>↑</span>
<span @click=
"orderFn('price', true)"
>↓</span>
</th>
<th>销量
<span @click=
"orderFn('sales', false)"
>↑</span>
<span @click=
"orderFn('sales', true)"
>↓</span>
</th>
</tr>
<tr v-
for
='(item, key) in list'>
<td>{{item.name}}</td>
<td>{{item.price}}</td>
<td>{{item.sales}}万</td>
</tr>
</table>
</p>
<script type=
"text/javascript"
>
var
myVueTest =
new
Vue({
el:'#box',
data:{
goodsList:[
{name:
"三星Galaxy Note8"
,price:5200,sales:2.6},
{name:
"iphone5s"
,price:2500,sales:2.2},
{name:
"iphone6"
,price:2800,sales:1.6},
{name:
"iphone6s"
,price:3200,sales:2.9},
{name:
"iphone7"
,price:3800,sales:12.6},
{name:
"iphone7plus"
,price:4200,sales:2.1},
{name:
"iphone8"
,price:5500,sales:10.6},
{name:
"华为"
,price:4600,sales:7.6},
{name:
"小米"
,price:1200,sales:32.6},
{name:
"OPPOR11"
,price:3000,sales:1.2},
{name:
"vivoX20"
,price:3250,sales:2.9}
],
searchVal:'',
letter:'',
original:false
},
methods:{
orderFn(letter,original){
this.letter = letter;
this.original = original;
}
},
computed:{
list:
function
(){
var
_this = this;
var
arrByZM = [];
for
(
var
i=0;i<this.goodsList.length;i++){
if
(this.goodsList[i].name.search(this.searchVal) != -1){
arrByZM.push(this.goodsList[i]);
}
}
if
(this.letter != ''){
arrByZM.sort(
function
( a , b){
if
(_this.original){
return
b[_this.letter] - a[_this.letter];
}
else
{
return
a[_this.letter] - b[_this.letter];
}
});
}
return
arrByZM;
}
}
});
</script>
</body>
</html>