File tree Expand file tree Collapse file tree 9 files changed +237
-17
lines changed Expand file tree Collapse file tree 9 files changed +237
-17
lines changed Original file line number Diff line number Diff line change 1+ <template >
2+ <div >
3+ <lai-checkbox-group v-model =" model" @on-change =" changeCheckbox" >
4+ <lai-checkbox :label =" 1" >复选框1</lai-checkbox >
5+ <lai-checkbox :label =" 2" >复选框2</lai-checkbox >
6+ <lai-checkbox :label =" 3" >复选框3</lai-checkbox >
7+ <lai-checkbox :label =" 4" >复选框4</lai-checkbox >
8+ </lai-checkbox-group >
9+ <p >{{model}}</p >
10+ </div >
11+ </template >
12+
13+ <script >
14+ import LaiCheckbox from " ./checkbox" ;
15+ import LaiCheckboxGroup from " ./checkboxGroup" ;
16+ export default {
17+ data () {
18+ return {
19+ model: [1 , 2 , 3 , 4 ],
20+ checkbox: true
21+ };
22+ },
23+ components: { LaiCheckbox, LaiCheckboxGroup },
24+ methods: {
25+ changeCheckbox (value ) {
26+ console .log (value);
27+ }
28+ }
29+ };
30+ </script >
31+
Original file line number Diff line number Diff line change @@ -88,7 +88,7 @@ export default {
8888 font-size : 14px ;
8989 & .lai-checkbox__checked {
9090 .lai-checkbox__icon {
91- background-color : #535ef5 ;
91+ background-color : #097cff ;
9292 }
9393 }
9494 & .lai-checkbox_disabled {
Original file line number Diff line number Diff line change 1+ <template >
2+ <div >
3+ <slot ></slot >
4+ </div >
5+ </template >
6+ <script >
7+ import { findChildren } from ' ../../utils'
8+ export default {
9+ name: ' lai-checkbox-group' ,
10+ props: {
11+ value: {
12+ type: Array ,
13+ default : () => []
14+ }
15+ },
16+ mounted () {
17+ this .updateChildrenModel ()
18+ },
19+ methods: {
20+ updateChildrenModel () {
21+ let children = findChildren (this , ' lai-checkbox' )
22+ for (let child of children) {
23+ child .model = this .value
24+ child .isChecked = (this .value .indexOf (child .label ) !== - 1 )
25+ }
26+ },
27+ updateModel (data ) {
28+ this .$emit (' input' , data)
29+ this .$emit (' on-change' , data)
30+ }
31+ },
32+ watch: {
33+ value (val ) {
34+ this .updateChildrenModel ()
35+ }
36+ }
37+ }
38+ </script >
39+
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ module.exports = {
66 serviceWorker : false ,
77 themeConfig : {
88 nav : [
9- // { text: 'Home', link: '/' },
9+ { text : 'Home' , link : '/' } ,
1010 { text : 'documents' , link : '/posts/' } ,
1111 { text : 'github' , link : 'https://google.com' } ,
1212 ] ,
@@ -30,12 +30,13 @@ module.exports = {
3030 ]
3131 } ,
3232 {
33- title : '组件 ' ,
33+ title : '组件案例 ' ,
3434 collapsable : false ,
3535 children : [
3636 '/posts/components/button' ,
3737 '/posts/components/message' ,
38- '/posts/components/modal'
38+ '/posts/components/modal' ,
39+ '/posts/components/checkbox'
3940 ]
4041 }
4142 ]
Original file line number Diff line number Diff line change 1+ let nodeList = [ ]
2+
3+ document . addEventListener ( 'click' , e => {
4+ nodeList . forEach ( node => {
5+ if ( ! node . el . contains ( e . target ) ) {
6+ node . callback ( )
7+ }
8+ } )
9+ } )
10+
11+ export default {
12+ inserted ( el , binding , vnode ) {
13+ if ( typeof binding . value !== 'function' ) {
14+ throw new TypeError ( 'v-clickOutside 的值必须是一个函数' )
15+ }
16+ let node = {
17+ el : el ,
18+ uid : vnode . context . _uid ,
19+ callback : binding . value
20+ }
21+ nodeList . push ( node )
22+ } ,
23+ unbind ( el , binding , vnode ) {
24+ for ( let i = 0 ; i < nodeList . length ; i ++ ) {
25+ if ( nodeList [ i ] . uid = vnode . context . _uid ) {
26+ nodeList . splice ( i , 1 )
27+ }
28+ }
29+ }
30+ }
Original file line number Diff line number Diff line change 1+ import loading from './loading.js'
2+ import clickOutside from './click-outside'
3+
4+ export default {
5+ loading,
6+ clickOutside
7+ }
Original file line number Diff line number Diff line change 1+ import Vue from 'vue'
2+ import LoadingComponent from '../components/loading'
3+ const Loading = Vue . extend ( LoadingComponent )
4+
5+ export default {
6+ inserted ( el , binding , vnode , oldVnode ) {
7+ console . log ( el )
8+ const child = document . createElement ( 'div' )
9+ const loadingText = el . getAttribute ( 'loading-text' )
10+ if ( binding . arg === 'fullPage' ) {
11+ document . body . appendChild ( child )
12+ } else {
13+ el . appendChild ( child )
14+ }
15+ const loading = new Loading ( {
16+ el : child ,
17+ data ( ) {
18+ return {
19+ isShow : binding . value ,
20+ loadingText : loadingText
21+ }
22+ }
23+ } )
24+ console . dir ( loading )
25+ el . loading = loading
26+ } ,
27+ update ( el , binding , vnode , oldVnode ) {
28+ // 更新loading组件的值
29+ el . loading . isShow = binding . value
30+ }
31+ }
Original file line number Diff line number Diff line change 11---
22home : true
3- heroImage : /hero.png
4- heroText : Hero 标题
5- tagline : Hero 副标题
6- actionText : 快速上手 →
7- actionLink : /zh/guide /
8- # features:
9- # - title: 简洁至上
10- # details: 以 Markdown 为中心的项目结构,以最少的配置帮助你专注于写作。
11- # - title: Vue驱动
12- # details: 享受 Vue + webpack 的开发体验,在 Markdown 中使用 Vue 组件,同时可以使用 Vue 来开发自定义主题。
13- # - title: 高性能
14- # details: VuePress 为每个页面预渲染生成静态的 HTML,同时在页面被加载的时候,将作为 SPA 运行。
15- # footer: MIT Licensed | Copyright © 2018-present Evan You
3+ heroImage : https://vuepress.vuejs.org /hero.png
4+ heroText : Vue的组件学习和开发
5+ tagline : Components Learning With Vue
6+ actionText : 快速开始 →
7+ actionLink : /posts /
8+ # features:
9+ # - title: 描述
10+ # details: 从零开始一个Vue组件的开发
11+ # - title: Vue
12+ # details: Vue ^2.5.17
13+ # - title: 文档
14+ # details: VuePress ^0.14.10
15+ # footer: '@https://github.com/zepang/lai-ui'
1616---
Original file line number Diff line number Diff line change 1+ # Checkbox 复选框
2+
3+ ##### 示例
4+
5+ <box >
6+ <checkbox-demo ></checkbox-demo >
7+ </box >
8+
9+ ##### 代码
10+
11+ ``` vue
12+ <template>
13+ <div>
14+ <lai-checkbox v-model="value">复选框</lai-checkbox>
15+ ...
16+ </div>
17+ </template>
18+ <script>
19+ ...
20+ export default {
21+ data () {
22+ return {
23+ value: false
24+ }
25+ },
26+ ...
27+ }
28+ </script>
29+
30+ ```
31+
32+ ##### 复选框组
33+
34+ <box >
35+ <checkbox-group-demo ></checkbox-group-demo >
36+ </box >
37+
38+ ##### 代码
39+
40+ ``` vue
41+ <template>
42+ <div>
43+ <lai-checkbox-group v-model="model" @on-change="changeCheckbox">
44+ <lai-checkbox :label="1">复选框1</lai-checkbox>
45+ <lai-checkbox :label="2">复选框2</lai-checkbox>
46+ <lai-checkbox :label="3">复选框3</lai-checkbox>
47+ <lai-checkbox :label="4">复选框4</lai-checkbox>
48+ </lai-checkbox-group>
49+ ...
50+ </div>
51+ </template>
52+
53+ <script>
54+ ...
55+ export default {
56+ data() {
57+ return {
58+ model: [1, 2, 3, 4],
59+ checkbox: true
60+ };
61+ },
62+ ...
63+ methods: {
64+ changeCheckbox(value) {
65+ console.log(value);
66+ }
67+ }
68+ };
69+ </script>
70+ ```
71+
72+ ##### API
73+ <box >
74+ <mk >
75+ | 属性 | 说明 | 类型 | 默认值 |
76+ | -------- | ---------------------------------------------------- | ------- | ------ |
77+ | value | 只在单独使用时有效。可以使用 v-model 双向绑定数据 | boolean | false |
78+ | label | 与 ` checkbox-group ` 组合使用有效 | String 或 Number 或 Boolean | - |
79+ | disabled | 设置为禁用状态 | Boolean | false |
80+ </mk >
81+ </box >
You can’t perform that action at this time.
0 commit comments