个人解决方案
来源:11-6 页面调试

Harrymissu
2019-02-25
老师在这章节留了两个作业。 这里写下个人解决方案给后来同学参考一下,有问题可以讨论哈, 欢迎指出错误以及改进的地方。
Q1:分别实现价格最低、人气最高、评价最高排序。
这部分的代码应该写在在list.vue中:
<dd
v-for="(item) in nav"
:key="item.name"
:class="[item.name,item.acitve?'s-nav-active':'']"
@click="navSelect(item.name)"
>{{ item.txt }}</dd>
navSelect: function (type) {
let self = this;
if (type === 's-price') {
self.nav[1].acitve = true;
self.nav[0].acitve = false;
self.nav[2].acitve = false;
self.nav[3].acitve = false;
let items = self.parentList;
items.sort(function (a,b) {
return a.price - b.price;
});
self.parentList = items;
} else if (type === 's-visit') {
self.nav[2].acitve = true;
self.nav[0].acitve = false;
self.nav[1].acitve = false;
self.nav[3].acitve = false;
let items = self.parentList;
items.sort(function (a,b) {
return b.comment - a.comment;
});
} else if (type === 's-comment') {
self.nav[1].acitve = false;
self.nav[0].acitve = false;
self.nav[2].acitve = false;
self.nav[3].acitve = true;
let items = self.parentList;
items.sort(function (a,b) {
return b.rate - a.rate;
});
}
},
但我觉得这样来修改active属性有点笨,各位有好点的想法没?
Q2:当鼠标滑到其他地点,地图坐标会随之改变到当前地点。
<Item
v-for="(item,idx) in parentList"
position="item.location"
:key="idx"
:meta="item"
@mouseover="over(item.location)"/>
item.location就是当前地点的坐标
over: function (location) {
//console.log(location)
this.$emit('currentPoint', location);
}
将这个坐标发送给父组件,也就是products.vue
<list
:list="list"
v-on:currentPoint="currentPoint"/>
父组件首先需要监听子组件,然后再将接受来自子组件的值
methods: {
currentPoint: function (currentPoint) {
this.point = currentPoint.split(',');
}
},
写回答
3回答
-
阿J脚步
2019-10-15
通过this.$emit()派发过去的事件没办法触发是什么原因呢
012019-10-15 -
阿J脚步
2019-10-15
棒!呆!了!
00 -
快乐动起来呀
2019-02-25
非常赞,可以把这个贡献到课程git的issue吗,方便大家欣赏
012019-02-25
相似问题