最近开发的项目 需要用input 的v-model 直接绑定到vuex的store数据 因为v-model 能与data的数据绑定 尝试了半天
代码如下
<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>
记录下备忘