最近開發的項目 須要用input 的v-model 直接綁定到vuex的store數據 由於v-model 能與data的數據綁定 嘗試了半天 vue
代碼以下vuex
<template> <div> <el-row class="age"> <el-col :span="3"> <div class="el-input__inner agestart"> <el-checkbox v-model="changeValue">年齡</el-checkbox> </div> </el-col> <el-col :span="4"> <el-input type="number" v-model="content" placeholder="開始年齡"></el-input> </el-col> <el-col :span="2"> <div class="el-input__inner ageto"> to </div> </el-col> <el-col :span="4"> <el-input type="number" v-model="contentend" placeholder="結束年齡"></el-input> </el-col> </el-row> </div> </template> <script> import { mapState } from 'vuex' export default { name:'Age', computed:{ changeValue:{ get(){ return this.$store.state.changeValue }, set(v){ this.$store.dispatch("changeMy",v) } }, content:{ get(){ return this.$store.state.startAge }, set(v){ this.$store.dispatch('changeMoney',v) } }, contentend:{ get(){ return this.$store.state.endAge }, set(v){ this.$store.dispatch('changeEndAge',v) } } } } </script> <style lang="stylus"> </style>
記錄下備忘this