Home  >  Article  >  Web Front-end  >  Summary of several ways to register components in Vue

Summary of several ways to register components in Vue

亚连
亚连Original
2018-05-31 16:30:202404browse

Below I will share with you a summary of several ways to register components in Vue. It has a good reference value and I hope it will be helpful to everyone.

1. Global registration (components registered in this way must be declared before vue is instantiated)

Vue.component('tag-name',{})

2. Partial registration

var Child = {
 template: &#39;<p>A custom component!</p>&#39;
}
new Vue({
 // ...
 components: {
 // <my-component> 将只在父模板可用
 &#39;my-component&#39;: Child
 }
})

3. Extended instance

// 定义一个混合对象
var myMixin = {
 created: function () {
 this.hello()
 },
 methods: {
 hello: function () {
  console.log(&#39;hello from mixin!&#39;)
 }
 }
}
// 定义一个使用混合对象的组件
var Component = Vue.extend({
 mixins: [myMixin]
})
var component = new Component() // -> "hello from mixin!"

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

Angular uses the operation event instruction ng-click to pass multiple parameters example

JavaScript code to implement txt File upload preview function

Angularjs implementation example summary of communication between controllers

The above is the detailed content of Summary of several ways to register components in Vue. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn