
Vue
实用技巧
Vue2
在父组件中监听子组件的生命周期钩子
vue
<template>
<child @hook:mounted="onChildMounted"></child>
</template>
<script>
export default {
methods: {
onChildMounted() {},
},
}
</script>
在 methods
中使用 debounce
/ throttle
vue
<template>
<div class="container" @click="handleClick"></div>
</template>
<script>
import { debounce } from 'lodash-es'
export default {
methods: {
// 猪猪:这里不能使用箭头函数,否则 this 会指向 window 或 undefined
handleClick: debounce(function () {}, 500)
}
}
</script>