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' }">
2018-01-23 19:00:20 +08:00
<a-checkbox
2017-11-06 17:46:08 +08:00
:checked="checked"
:disabled="disabled"
@change="onChange"
>
{{label}}
2018-01-23 18:55:39 +08:00
</a-checkbox>
2017-11-06 17:46:08 +08:00
</p>
<p>
2018-01-23 18:55:39 +08:00
<a-button
2017-11-06 17:46:08 +08:00
type="primary"
size="small"
@click="toggleChecked"
>
{{!checked ? 'Check' : 'Uncheck'}}
2018-01-23 18:55:39 +08:00
</a-button>
<a-button
2017-11-06 17:46:08 +08:00
:style="{ marginLeft: '10px' }"
type="primary"
size="small"
@click="toggleDisable"
>
{{!disabled ? 'Disable' : 'Enable'}}
2018-01-23 18:55:39 +08:00
</a-button>
2017-11-06 17:46:08 +08:00
</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,
2018-01-23 18:55:39 +08:00
2017-11-03 18:46:18 +08:00
},
}
</script>