GithubHelp home page GithubHelp logo

vue-gold-mixin's Introduction

vue-gold-mixin

  • v-model
  • sync props

v-model

Whenever you need to have a component directiv vmodel, just add this mixin to it. You can easily separate the components

You can access it with the selfValue key.

haw to use :

your component

<template>
  <div>
      <v-text-field
        v-model="selfValue"
      />
  </div>
</template>

<script>
import { modelMixin } from '@/modules/mixins'
export default {
  name: 'CInput',
  mixins: [modelMixin]
}
</script>

use component

<template>
  <div>
    <label>username :</label>
      <c-input v-model="username"/>
  </div>
</template>

<script>
export default {
  data(){
    return {
      username : ''
    }
  }
}
</script>

sync props

If you want to use the prop sync feature (almost similar to vmodel) it has its own problems and your code gets a little dirty

Here it is enough for you to use this mixin and give it a list of your props names with the _sync method.

You now have access to it with sync_nameYourProp, and any changes you make to it apply to your parent.

The example below is a combination of the example above .

your component :

<template>
  <div>
      <v-text-field
        v-model="selfValue"
      />
    <label>
      {{selfValue}}
    </label>
  </div>
</template>

<script>
import { modelMixin,syncProps } from '@/modules/mixins'
export default {
  name: 'CInput',
  mixins: [modelMixin,syncProps],
  props:{
    passwordShow : {
      type: Boolean,
      default : false
    }
  },
  method:{
    _sync(){
      return ['passwordShow']
    }
  }
}
</script>

use component :

<template>
  <div>
    <label>password :</label>
    <c-input v-model="password" :password-show.sync="passShow"/>
    <c-input v-model="verifyPassword" :password-show.sync="passShow"/>
    <button
    @click="passShow = !passShow"
    >
      show
    </button>
  </div>
</template>

<script>
export default {
  data () {
    return {
      password: '',
      verifyPassword: '',
      passShow: false
    }
  }
}
</script>


vue-gold-mixin's People

Contributors

iransoftnet1 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.