首页 > 代码库 > vue前端data传给action

vue前端data传给action

 

1.vue-view

<el-input v-model="u.name" placeholder="请输入用户名"></el-input><el-input v-model="u.pwd" placeholder="请输入密码"></el-input><button @click=‘login‘>登录</button>

2.vue-data

export default {  name:‘login‘,  data:() =>({    u:{name: ‘abc‘,pwd:‘123‘}  }), //箭头函数返回对象时,需要将对象包裹在小括号里}

3.vue-method

methods:{    login() {this.$store.dispatch(‘fun‘,this.u)}, //调用action中的方法}

4.vuex-action

export const fun = ({ commit,state },u) => { //action只能接受两个参数  alert(u.name+","+u.pwd)}

 

vue前端data传给action