vue-learning:24 - component - 目录
component 组件
- 组件的概念
Vue 组件同时也都是 Vue 实例,可接受相同的选项对象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 } } } - prop的命名规范
- 动态prop(除字符串外,其它类型传入都需要使用动态prop,即v-bind绑定)
- 单向数据流和prop实现双向绑定.sync修饰符
- 非prop特性
- 被替换或合并
- 禁用继承
inheritAttr: false $attr
event
v-on / $on监听事件$once一次性事件$emit触发事件$off卸载事件监听$listenersv-on绑定监听器集合(除原生监听事件).native原生事件修饰符.sync双向绑定修饰符model属性
slot
- 普通插槽
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> - 解构插槽prop
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>- 模板编译作用域
父级模板里的所有内容都是在父级作用域中编译的;子模板里的所有内容都是在子作用域中编译的。
- 字符串数组形式:
- 组件依赖注入
provideinject
- 组件实例的引用
ref / $refs$root$parent$children自定义扩展方法
- 组件间的通信
- 父子组件通信
prop / $emit - 嵌套组件
$attrs/$liteners - 后代组件通信
provide / inject - 组件实例引用
$root/$parent/$children/$refs - 事件总线
const Bus = new Vue() - 状态管理器
Vuex
- 父子组件通信
- 动态组件
<component is="com-name"></component> - 异步组件
function 内置组件
transiton/keep-alive/component- 其它
- 组件的递归调用
- 组件的循环引用
v-once创建静态组件
vue-learning:24 - component - 目录的更多相关文章
- vue中extend/component/mixins/extends的区别
vue中extend/component/mixins/extends的区别 教你写一个vue toast弹窗组件 Vue.extend构造器的延伸
- vue中的项目目录assets和staitc的区别
vue中的项目目录assets和staitc的区别 在进行发行正式版时,即为npm run build编译后, assets下的文件如(js.css)都会在dist文件夹下面的项目目录分别合并到一个文 ...
- 第六章 组件 59 组件切换-使用Vue提供的component元素实现组件切换
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8&quo ...
- Vue Login Form Component
Vue Login Form Component Account Login <template> <div> <slot></slot> <el ...
- Vue Learning Paths
Vue Learning Paths Vue Expert refs https://vueschool.io/articles/vuejs-tutorials/exciting-new-featur ...
- vue 组件复用 - component
vue 组件复用 - component vue 组件复用 就是对 component 标签的使用 先看图 下图看使用 结果: 可以看到 在箱包 这一项,我将banner 组件用了两次,我 每次 点击 ...
- 从零开始:一个正式的vue+webpack项目的目录结构是怎么形成的
如何从零开始一个vue+webpack前端工程工作流的搭建,首先我们先从项目的目录结构入手.一个持续可发展,不断加入新功能,方便后期维护的目录结构究竟是长什么样子的?接下来闰土大叔带你们一起手摸手学起 ...
- vue源码分析—Vue.js 源码目录设计
Vue.js 的源码都在 src 目录下,其目录结构如下 src ├── compiler # 编译相关 ├── core # 核心代码 ├── platforms # 不同平台的支持 ├── ser ...
- vue项目开发基本目录结构
§ 目录结构 . ├── build/ # Webpack 配置目录 ├── dist/ # build 生成的生产环境下的项目 ├── src/ # 源码目录(开发都在这里进行) │ ├── ass ...
随机推荐
- python 定义子类
- oracle限制一个用户空闲时间
alter system set resource_limit = true; create profile idletime limit idle_time 3; alter user outln ...
- TCPThree_C杯 Day2
T1 我已经被拉格朗日插值蒙蔽了双眼,变得智障无比. 第一反应就是拉格朗日插值,然后就先放下了它. 模数那么小,指数那么大,这是一套noip模拟题,拉格朗日,你脑袋秀逗了? 无脑暴力20分贼开心. 正 ...
- laravel 操作日志;
在网上寻找了许多方法,觉得有的地方看不懂, 决定自己写一些关于laravel中调用本身中的操作日志: Laravel 日志工具在强大的 Monolog 函数库上提供一层简单的功能.Laravel 默 ...
- SDUT-3361_迷宫探索
数据结构实验之图论四:迷宫探索 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 有一个地下迷宫,它的通道都是直的,而通道 ...
- bzoj4152 The Captain
Description 给定平面上的n个点,定义(x1,y1)到(x2,y2)的费用为min(|x1-x2|,|y1-y2|),求从1号点走到n号点的最小费用. Input 第一行包含一个正整数n(2 ...
- python-selenium自动化测试(火狐、谷歌、360浏览器启动)
一.打开谷歌浏览器 import selenium from selenium import webdriver browser = webdriver.Chrome(executable_path ...
- Datagrid添加右键菜单 标签: 三层EasyUI 2015-08-14 19:57 1029人阅读 评论(22)
最近的一个项目前台使用的EasyUI,每个界面都有DataGrid控件,按照我们的想法,应该做出来的效果是单击选中,双击可编辑,当然右键也应该出现这些菜单按钮,想的挺好,那么该如何实现呢?一开始不知道 ...
- 04使用harbor配置私仓
安装harbor之前,需要安装好Python,Docker,DockerCompose.Python需要2.7以上的版本,Docker需要1.10以上的版本:Docker Compose 需要1.6. ...
- 删除username的索引
-- 删除index_name 索引 drop index index_name on user; show index from user \G; -- 创建新索引列组成,index_pinyin为 ...