2019-07-17 01:35:11 +08:00
|
|
|
/**
|
2019-07-17 14:40:28 +08:00
|
|
|
* 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
|
|
|
|
* })
|
|
|
|
* }
|
|
|
|
* }
|
2019-07-17 01:35:11 +08:00
|
|
|
*/
|
|
|
|
export default {
|
|
|
|
model: {
|
|
|
|
prop: 'active',
|
2019-07-17 14:11:05 +08:00
|
|
|
event: 'setactive'
|
2019-07-17 01:35:11 +08:00
|
|
|
},
|
|
|
|
props: {
|
|
|
|
active: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
deactivate () {
|
2019-07-17 14:11:05 +08:00
|
|
|
// console.log('deactivate')
|
|
|
|
this.$emit('setactive', false)
|
2019-07-17 01:35:11 +08:00
|
|
|
},
|
|
|
|
activate () {
|
2019-07-17 14:11:05 +08:00
|
|
|
// console.log('activate')
|
|
|
|
this.$emit('setactive', true)
|
|
|
|
},
|
|
|
|
toggle () {
|
|
|
|
if (this.active) this.deactivate()
|
|
|
|
else this.activate()
|
2019-07-17 01:35:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|