Vue.js override mounted()方法
因此,我以这种方式扩展了我的组件:Vue.js override mounted()方法,vue.js,Vue.js,因此,我以这种方式扩展了我的组件: <template> <qlist></qlist> </template> <script> import QuestionList from '@/components/pages/questions/QuestionList' export default { extends: QuestionList, components: { 'qlist': QuestionList
<template>
<qlist></qlist>
</template>
<script>
import QuestionList from '@/components/pages/questions/QuestionList'
export default {
extends: QuestionList,
components: {
'qlist': QuestionList
}
}
</script>
<style scoped>
</style>
从“@/components/pages/questions/QuestionList”导入问题列表
导出默认值{
扩展:问题列表,
组成部分:{
“qlist”:问题列表
}
}
如何完全重写问题列表组件中的mounted()方法?我注意到,当我在当前组件中定义它时,我可以向mounted()方法添加功能,但我无法覆盖以前的行为您的组件导入QuestionList以将其作为模板中的元素,因此将调用QuestionList的mounted()钩子中的任何内容,你不能避免这样做。使用mixin:将原始组件和扩展它的组件中应该相同的所有逻辑放在其中,并分别在每个组件中实现mounted()。移动你的坐骑()将逻辑挂钩到方法,您甚至可以使用此处所述的自定义合并选项:但这可能不是必需的。扩展组件时,请不要忘记,Vue会将同名挂钩组合到一个数组中—来自父级的挂钩位于数组的末尾,而来自组件的同名挂钩则扩展到数组的开头数组的一部分。