SHARE
TWEET

Untitled

a guest Dec 3rd, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. export default function toggleable (children = [], prop = 'active', event = 'toggle') {
  2.   return {
  3.     name: 'toggleable',
  4.     model: { prop, event },
  5.     data () {
  6.       return {
  7.         isActive: !!this[prop]
  8.       }
  9.     },
  10.     props: {
  11.       [prop]: { required: false }
  12.     },
  13.     watch: {
  14.       [prop] (val) {
  15.         this.isActive = !!val
  16.       },
  17.       isActive (val) {
  18.         !!val !== this[prop] && this.$emit(event, val)
  19.       }
  20.     },
  21.     methods: {
  22.       include () {
  23.         let refs = []
  24.         for (let child of children) {
  25.           refs.push(this.$refs[child])
  26.         }
  27.         return refs
  28.       },
  29.       toggle (value) {
  30.         this.isActive = value !== undefined ? value : !this.isActive
  31.       }
  32.     }
  33.   }
  34. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top