support Switch

support Switch
This commit is contained in:
梁灏 2017-03-02 11:19:00 +08:00
parent e31ab8ad7e
commit 2d5ba27837
7 changed files with 41 additions and 31 deletions

View file

@ -8,3 +8,5 @@ value 改为了 label使用 v-model废弃 checked
使用 v-model
### CheckboxGroup
value 改为了 label使用 v-model废弃 checked
### Switch
废弃checked 改为了 value使用 v-model

View file

@ -23,7 +23,7 @@
- [x] Input
- [x] Radio
- [x] Checkbox
- [ ] Switch
- [x] Switch
- [ ] Table
- [ ] Select
- [ ] Slider

View file

@ -1,8 +1,8 @@
<template>
<span :class="wrapClasses" @click="toggle">
<span :class="innerClasses">
<slot name="open" v-if="checked"></slot>
<slot name="close" v-if="!checked"></slot>
<slot name="open" v-if="currentValue"></slot>
<slot name="close" v-if="!currentValue"></slot>
</span>
</span>
</template>
@ -13,7 +13,7 @@
export default {
props: {
checked: {
value: {
type: Boolean,
default: false
},
@ -27,12 +27,17 @@
}
}
},
data () {
return {
currentValue: this.value
}
},
computed: {
wrapClasses () {
return [
`${prefixCls}`,
{
[`${prefixCls}-checked`]: this.checked,
[`${prefixCls}-checked`]: this.currentValue,
[`${prefixCls}-disabled`]: this.disabled,
[`${prefixCls}-${this.size}`]: !!this.size
}
@ -48,9 +53,17 @@
return false;
}
this.checked = !this.checked;
this.$emit('on-change', this.checked);
this.$dispatch('on-form-change', this.checked);
const checked = !this.currentValue;
this.currentValue = checked;
this.$emit('input', checked);
this.$emit('on-change', checked);
// todo
// this.$dispatch('on-form-change', this.checked);
}
},
watch: {
value (val) {
this.currentValue = val;
}
}
};

View file

@ -32,7 +32,7 @@ import Radio from './components/radio';
// import Slider from './components/slider';
// import Spin from './components/spin';
import Steps from './components/steps';
// import Switch from './components/switch';
import Switch from './components/switch';
// import Table from './components/table';
// import Tabs from './components/tabs';
// import Tag from './components/tag';
@ -98,7 +98,7 @@ const iview = {
// Spin,
Step: Steps.Step,
Steps,
// Switch,
iSwitch: Switch,
// iTable: Table,
// Tabs: Tabs,
// TabPane: Tabs.Pane,

View file

@ -21,6 +21,7 @@ li + li { border-left: solid 1px #bbb; padding-left: 10px; margin-left: 10px; }
<li><router-link to="/checkbox">Checkbox</router-link></li>
<li><router-link to="/steps">Steps</router-link></li>
<li><router-link to="/timeline">Timeline</router-link></li>
<li><router-link to="/switch">Switch</router-link></li>
</ul>
</nav>
<router-view></router-view>

View file

@ -48,6 +48,10 @@ const router = new VueRouter({
{
path: '/timeline',
component: require('./routers/timeline.vue')
},
{
path: '/switch',
component: require('./routers/switch.vue')
}
]
});

View file

@ -1,33 +1,23 @@
<template>
<Switch @on-change="change"></Switch>
<Switch>
<div>
<i-switch v-model="m1">
<span slot="open"></span>
<span slot="close"></span>
</Switch>
<Switch size="large">
<span slot="open">ON</span>
<span slot="close">OFF</span>
</Switch>
<Switch>
<Icon type="android-done" slot="open"></Icon>
<Icon type="android-close" slot="close"></Icon>
</Switch>
<Switch :disabled="disabled"></Switch>
<i-button type="primary" @click="disabled = !disabled">Toggle Disabled</i-button>
<Switch size="small"></Switch>
</i-switch>
{{ m1 }}
<div @click="m1 = !m1">toggle</div>
</div>
</template>
<script>
import { Switch, Message, iButton, Icon } from 'iview';
export default {
components: { Switch, Message, iButton, Icon },
data () {
return {
disabled: true
m1: false
}
},
methods: {
change (status) {
Message.info('开关状态:' + status);
console.log(status)
}
}
}