如何在单文件组件中扩展另一个 VueJS 组件?(ES6 vue-loader) [英] How do I extend another VueJS component in a single-file component? (ES6 vue-loader)
问题描述
我正在使用 vue-loader 来构建我的 *.vue
单文件组件,但我在从另一个文件组件扩展单文件组件的过程中遇到问题.
I am using vue-loader to construct my *.vue
single-file components, but I am having trouble with the process of extending a single-file component from another.
如果一个组件遵循规范以 export default { [component "Foo";定义] }
,我认为这只是导入这个组件的问题(就像我对任何子组件一样)然后 export default Foo.extend({ [extended component definition] })代码>
If one component follows the spec to export default { [component "Foo" definition] }
, I would think it is just a matter of importing this component (as I would with any child component) and then export default Foo.extend({ [extended component definition] })
不幸的是,这不起作用.任何人都可以提供建议吗?
Unfortunately this does not work. Can anyone please offer advice?
推荐答案
正确的做法是使用 mixins:http://vuejs.org/guide/mixins.html
The proper way to do this would be to use mixins: http://vuejs.org/guide/mixins.html
将 mixin 视为抽象组件,您可以对其进行扩展.因此,您可以创建一个具有您希望在两者中都具有的任何功能的 mixin,然后将其应用于您的每个组件.
Think of mixins as abstract components, which you can extend. So you could create a mixin with any functionality you wanted to have in both, and then just apply it to each of your components.
这篇关于如何在单文件组件中扩展另一个 VueJS 组件?(ES6 vue-loader)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!