vue v-model 与 vuex state数据绑定问题

最近开发的项目 需要用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>

记录下备忘

转载于:https://www.cnblogs.com/junwu/p/10754426.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值