mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2024-12-27 05:00:48 +08:00
61 lines
1.1 KiB
JavaScript
61 lines
1.1 KiB
JavaScript
/**
|
|
* Toggle prop active use v-model
|
|
*
|
|
* @prop {boolean} active
|
|
*
|
|
* So if you want to your component to work with itself using this mixin, you
|
|
* need to wrap it.
|
|
* for example:
|
|
* export default {
|
|
* data () {
|
|
* return {
|
|
* active: false
|
|
* }
|
|
* },
|
|
* ...,
|
|
* methods: {
|
|
* handleSetActive (active) {
|
|
* this.active = active
|
|
* }
|
|
* },
|
|
* render (h) {
|
|
* on = {
|
|
* handleSetActive: this.setActive.bind(this)
|
|
* }
|
|
* return h(MyComponent, {
|
|
* props: { .
|
|
* ..this.$props,
|
|
* active: this.active
|
|
* },
|
|
* on
|
|
* })
|
|
* }
|
|
* }
|
|
*/
|
|
export default {
|
|
model: {
|
|
prop: 'active',
|
|
event: 'setactive'
|
|
},
|
|
props: {
|
|
active: {
|
|
type: Boolean,
|
|
default: false
|
|
}
|
|
},
|
|
methods: {
|
|
deactivate () {
|
|
// console.log('deactivate')
|
|
this.$emit('setactive', false)
|
|
},
|
|
activate () {
|
|
// console.log('activate')
|
|
this.$emit('setactive', true)
|
|
},
|
|
toggle () {
|
|
if (this.active) this.deactivate()
|
|
else this.activate()
|
|
}
|
|
}
|
|
}
|