Home > Web Front-end > JS Tutorial > body text

Summary of several ways to register components in Vue

亚连
Release: 2018-05-31 16:30:20
Original
2453 people have browsed it

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',{})
Copy after login

2. Partial registration

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

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!"
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!