ant-design-vue/components/checkbox/demo/controller.vue

63 lines
1.2 KiB
Vue
Raw Normal View History

2017-11-03 18:46:18 +08:00
<template>
<div>
2017-11-06 17:46:08 +08:00
<p :style="{ marginBottom: '20px' }">
<Checkbox
:checked="checked"
:disabled="disabled"
@change="onChange"
>
{{label}}
</Checkbox>
</p>
<p>
<AntButton
type="primary"
size="small"
@click="toggleChecked"
>
{{!checked ? 'Check' : 'Uncheck'}}
</AntButton>
<AntButton
:style="{ marginLeft: '10px' }"
type="primary"
size="small"
@click="toggleDisable"
>
{{!disabled ? 'Disable' : 'Enable'}}
</AntButton>
</p>
2017-11-03 18:46:18 +08:00
</div>
</template>
<script>
2017-11-06 17:46:08 +08:00
import { Checkbox, Button } from 'antd'
2017-11-03 18:46:18 +08:00
export default {
2017-11-06 17:46:08 +08:00
data () {
return {
checked: true,
disabled: false,
}
},
computed: {
label () {
const { checked, disabled } = this
return `${checked ? 'Checked' : 'Unchecked'}-${disabled ? 'Disabled' : 'Enabled'}`
},
},
2017-11-03 18:46:18 +08:00
methods: {
2017-11-06 17:46:08 +08:00
toggleChecked () {
this.checked = !this.checked
},
toggleDisable () {
this.disabled = !this.disabled
},
2017-11-03 18:46:18 +08:00
onChange (e) {
2017-11-06 17:46:08 +08:00
this.checked = e.target.checked
2017-11-03 18:46:18 +08:00
},
},
components: {
Checkbox,
2017-11-06 17:46:08 +08:00
AntButton: Button,
2017-11-03 18:46:18 +08:00
},
}
</script>