认真学习前端第四天打卡
1.组件通信:
1.父子组件:
父->子:父组件在子组件标签里(响应式v-bind)自定义属性传递;子组件通过props属性接收
子->父:子组件实例自定义事件($emit),父组件中子组件监听这个事件(v-on)
2.兄弟组件:
$emit->$on(挂载后mounted)
3.依赖注入(避免props逐级透传):
父组件从vue导入provide->provide(注入名,值)
子组件从vue导入inject->message=inject(注入名)
4.直接通过$parent和$children获取实例
this.$children[0].message
this.$parent.msg
5.ref /refs
<son ref="sonDate"></son>
const sonDate= this.$refs.sonDate
2.排序的方法
1.people.sort((a, b) => a.age - b.age);按照年龄升序排列//默认升序undefined被排到最后
2.array.prototype.tosorted();升序
3.array.sortby();对多个数组排序
3.数组去重
1.Array.from(new set(arr));es6的set,无法去掉空对象
2.for循环用splice去重
3.创建一个新的数组,用indexof在新数组里查找
4.先sort,然后找前后是否相同