如何在单个文件组件中扩展另一个VueJS组件? (ES6 vue-loader) [英] How do I extend another VueJS component in a single-file component? (ES6 vue-loader)

查看:137
本文介绍了如何在单个文件组件中扩展另一个VueJS组件? (ES6 vue-loader)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用vue-loader( http://vuejs.github.io /vue-loader/start/spec.html )构造我的 *。vue 单个文件组件,但是我在扩展过程中遇到麻烦导出默认{[组件Foo定义]}

I am using vue-loader (http://vuejs.github.io/vue-loader/start/spec.html) to construct my *.vue single-file components, but I am having trouble with the process from extending a single-file component from another.

如果一个组件按照规范执行 $ c>,我认为这只是一个导入这个组件的问题(就像我想要的任何一个子组件),然后 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

将mixins视为抽象组件,您可以扩展它们。所以你可以创建一个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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆