component

Today’s front-end domain, with its high requirements for code quality and data, is particularly problematic with managing code as a component: a component that can be used over and over again, with a specified function View.

Create components

(1) Create components

Vue.component("Component Name",{component content,template:'< h3 > module < / h3 >'}); Ponent (example: Vue.com"my-component",{
template:'< h3 > module < / h3 >'});
Copy the code

(2) Use of components: Components are used just like a normal HTML tag

<my-component></my-component>
Copy the code

(2) If multiple elements are rendered in a component, put the multiple elements in a root tag, otherwise an error is reported

The component life cycle is divided into four phases

The create/mount/update/destroy (mount)

Each stage has the corresponding handler function create:beforeCreate Created (1) {create: initialize operation} mount:beforeMount Mounted (1) {mount DOM tree} update:beforeUpdate Updated (n) {data update -> Operation or logic judgment} destroy:beforeDestroy destroyed(1) {cleanup}