1. vue2-redux

vue2-redux

Vue2 Redux

Vue bindings for for Redux in only 1.06 kB. ⏭

Installation

npm install vue2-redux --save

Setup in project

 import Vue from "vue";
import { VueRedux } from "vue2-redux";
import App from "./components/App.vue";
/**
 * Your redux store is exported here like
 * so: `export default createStore( combineReducers( ... ) )`.
 */
import Store from "./store";

Vue.use(VueRedux(Store));

new Vue({
  el: "#app",
  render: h => h(App)
});

Using in a component

 <template>
  <div id="app">
    <div v-if="!username">Please enter your username</div>
    <div v-else>Your username is: {{ username }}</div>
    <input @keyup="handleUsernameChange" type="text" />
  </div>
</template>

<script>
  import { connect } from 'vue2-redux'
  import { updateUsername } from '../actions/User'

  const component = {
    name: "app-container",
    methods: {
      handleUsernameChange({ target: { value } }) {
        this.updateUsername(value)
      }
    }
  }

  const mapState = state => ({
    username: state.User.username
  })

  const mapDispatch = dispatch => ({
    updateUsername: nextUsername => dispatch(updateUsername(nextUsername))
  })

  export default connect(mapState, mapDispatch)(component)

</script>

Special note

This WILL NOT work if your .babelrc has:

 {
  "presets": [["env"], { "modules": false }]
}

This MUST BE changed to:

 {
  "presets": [["env"]]
}

Dependencies

babel-cli: ^6.3.17babel-core: ^6.3.26babel-eslint: ^7.1.1babel-plugin-check-es2015-constants: ^6.3.13babel-plugin-external-helpers: ^6.22.0babel-plugin-istanbul: ^4.0.0babel-plugin-syntax-jsx: ^6.3.13babel-plugin-transform-decorators-legacy: ^1.2.0babel-plugin-transform-es2015-arrow-functions: ^6.3.13babel-plugin-transform-es2015-block-scoped-functions: ^6.3.13babel-plugin-transform-es2015-block-scoping: ^6.3.13babel-plugin-transform-es2015-classes: ^6.3.13babel-plugin-transform-es2015-computed-properties: ^6.3.13babel-plugin-transform-es2015-destructuring: ^6.3.13babel-plugin-transform-es2015-for-of: ^6.3.13babel-plugin-transform-es2015-function-name: ^6.3.13babel-plugin-transform-es2015-literals: ^6.3.13babel-plugin-transform-es2015-modules-commonjs: ^6.3.13babel-plugin-transform-es2015-object-super: ^6.3.13babel-plugin-transform-es2015-parameters: ^6.3.13babel-plugin-transform-es2015-shorthand-properties: ^6.3.13babel-plugin-transform-es2015-spread: ^6.3.13babel-plugin-transform-es2015-sticky-regex: ^6.3.13babel-plugin-transform-es2015-template-literals: ^6.3.13babel-plugin-transform-es2015-unicode-regex: ^6.3.13babel-plugin-transform-object-rest-spread: ^6.3.13babel-plugin-transform-react-display-name: ^6.4.0babel-plugin-transform-react-jsx: ^6.4.0babel-register: ^6.3.13codecov: ^2.2.0create-react-class: ^15.5.3cross-env: ^5.0.1es3ify: ^0.2.0eslint: ^4.0.0eslint-plugin-import: ^2.2.0eslint-plugin-react: ^7.1.0expect: ^1.8.0glob: ^7.1.1istanbul: ^0.4.4jsdom: ^11.0.0mocha: ^3.2.0nyc: ^11.0.2react: ^15.5.4react-dom: ^15.5.4redux: ^3.0.0rimraf: ^2.3.4rollup: ^0.43.0rollup-plugin-babel: ^2.7.1rollup-plugin-commonjs: ^8.0.2rollup-plugin-node-resolve: ^3.0.0rollup-plugin-replace: ^1.1.1rollup-plugin-uglify: ^2.0.1