1. What is the component of communication? Why should communicate with components?
- Assembly is integrally having individual functions, to make connections between them together with the used, it is necessary to establish communication.
2. way communication There are several components?
- Sons components of the communication (achieved by props)
- Child-parent communication components (custom events)
- Sons non-communication assembly (REF chain bus event bus)
- Multi-state sharing component (a common multi-component data Vuex)
3.app instance manually mount
new Vue({
}).$mount('#app')
4. Custom Event
- Since the adoption $ on the definition, $ emit defined trigger
var vm = new Vue({
el: '#app'
})
// vm.$on(自定义事件的名称,自定义事件的事件处理程序)
vm.$on( 'aa', function () {
console.log( 'aa' )
})
// vm.$emit( 自定义事件的名称,自定义事件处理程序需要的参数1,参数2,参数3)
vm.$emit( 'aa' )
- By binding the component body is defined by $ emit trigger,
- Use: child father communication
<Son @aa = "fn"/>
Dynamic Components
- What is the dynamic components?
Components can be changed - Use
provided by a component + is attribute Vue - Dynamic component refers to the component this component
- Case
<div id="app"> <button @click = "change"> 切换 </button> <keep-alive include=""> <component :is = "type"></component> </keep-alive> </div>
Vue.component('Aa',{ template: '<div> Aa </div>' }) Vue.component('Bb',{ template: '<div> Bb </div>' }) new Vue({ data: { type: 'Aa' }, methods: { change () { this.type = (this.type === 'Aa'?'Bb':'Aa') } } }).$mount('#app')
- Vue provides a component called the keep-alive of our components can be browser cache, so that when we switch components, can greatly improve efficiency
- keep-alive can also be presented in the form of property, but if we mix component, it is recommended to use component form
slot slot
- Role / concept: the future content to be used in advance to be retained
- Named slots: slot to a name
- Note: in the above two forms is discarded above vue2.6
- Why use v-slot command to replace it?
- Unified through the slot named slot and scope
- The concept of instructions: To these two properties with vue logo, and meet one of the two largest properties vue