Vue.extend 有什么用? [英] What is Vue.extend for?

查看:75
本文介绍了Vue.extend 有什么用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个足够简单的方法,但我没有从文档中得到我需要的答案.我正在学习Vue.js,我真的不明白Vue.extend适合什么地方.我得到了Vue.component,但我没有看到Vue.extend 做了什么 Vue.component 没有.它只是 1.0 的遗留功能吗?如果没有,那么它在 Vue 2.0 中哪里有用?

This is a simple enough one, but I'm not getting the answer I need from the documentation. I'm in the process of learning Vue.js, and I don't really understand where Vue.extend fits in. I get Vue.component, but I don't see what Vue.extend does which Vue.component doesn't. Is it just a legacy feature from 1.0? If not, where is it useful in Vue 2.0?

推荐答案

他们在之前的 Vuejs.org 站点中的指南有一个文档.

Their guide in the previous Vuejs.org site had a document.

复制自 http://optimizely.github.io/vuejs.org/guide/composition.html 是从 vuejs/Vuejs.org 在 Vuejs 0.10.6 版本分叉出来的.

Copied from http://optimizely.github.io/vuejs.org/guide/composition.html which is forked from vuejs/Vuejs.org at version 0.10.6 of Vuejs.

了解 Vue.extend() 之间的区别很重要和 Vue.component().由于 Vue 本身就是一个构造函数,Vue.extend() 是一种类继承方法.它的任务是创建 Vue 的子类并返回构造函数.Vue.component(),另一方面,是一个资产注册方法类似于Vue.directive()Vue.filter().它的任务是将给定的构造函数与字符串 ID 相关联,以便 Vue.js 可以选择它在模板中.当直接将选项传递给Vue.component(),它在底层调用了 Vue.extend().

It is important to understand the difference between Vue.extend() and Vue.component(). Since Vue itself is a constructor, Vue.extend() is a class inheritance method. Its task is to create a sub-class of Vue and return the constructor. Vue.component(), on the other hand, is an asset registration method similar to Vue.directive() and Vue.filter(). Its task is to associate a given constructor with a string ID so Vue.js can pick it up in templates. When directly passing in options to Vue.component(), it calls Vue.extend() under the hood.

Vue.js 支持两种不同的 API 范式:基于类的,命令式、Backbone 风格的 API 和基于标记的声明式 Web组件样式 API.如果您感到困惑,请考虑如何使用 new Image() 标签创建图像元素.每一个都有自己的用处,Vue.js 试图同时提供最大的灵活性.

Vue.js supports two different API paradigms: the class-based, imperative, Backbone style API, and the markup-based, declarative, Web Components style API. If you are confused, think about how you can create an image element with new Image(), or with an <img> tag. Each is useful in its own right and Vue.js tries to provide both for maximum flexibility.

这篇关于Vue.extend 有什么用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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