标签:name learning 构建 component otn als 内容 efault 全局
option (除了一些根级特有的选项) 和使用相同的生命周期钩子,以及模板调用方式。com = Vue.extend(option)Vue.component(‘my-com‘, com)vm.components: {‘my-com‘: com}Vue.component(‘my-com‘,option) vm.components(‘my-com‘: option)组件三大API: prop / event / slot
prop
props: [‘prop1‘, ‘prop2‘, ...]js props: {prop1: Number} props: { prop1: { type: [Number, String], required: true, default: 100, //当默认值是对象或数组时,必须从函数返回值获取 () => { return value } validator: (value) => { // do somethings return Boolean return result } } }inheritAttr: false$attrv-on / $on 监听事件$once 一次性事件$emit 触发事件$off 卸载事件监听$listeners v-on绑定监听器集合(除原生监听事件).native 原生事件修饰符.sync 双向绑定修饰符model 属性html <slot></slot>html <slot>default content</slot>html <slot name="someName"></slot> <!-- 组件调用 --> <my-com> <template v-slot:somName></template> <my-com>html <slot :prop="value"></slot> <!--组件调用 --> <my-com> <template v-slot=‘childValue‘>{{ cilidValue.value}}</template> </my-com>html <some-component v-slot="childValue"> {{ childValue.value }}</some-component> <some-component v-slot:default="childValue"> {{ childValue.value }}</some-component>html <my-com v-slot="{value}">{{ value }}</my-com> <!-- 重命名 --> <my-com v-slot="{value: otherName}">{{ otherName }}</my-com> <!-- 重命名并提供默认值 --> <my-com v-slot="{value: {otherName: defaultValue}}">{{ otherName }}</my-com>html <my-com> <template v-slot:[dynamicSlotName]></template> </my-com>v-slot 的简写 #html <my-com> <template #somName></template> <my-com>provideinjectref / $refs$root$parent$children自定义扩展方法prop / $emit$attrs / $litenersprovide / inject$root / $parent / $children / $refsconst Bus = new Vue()Vuex<component is="com-name"></component>function内置组件transiton / keep-alive / component
v-once创建静态组件vue-learning:24 - component - 目录
标签:name learning 构建 component otn als 内容 efault 全局
原文地址:https://www.cnblogs.com/webxu20180730/p/11031227.html