1. I don"t understand many places when I use vuex, for the first time. The account number and password entered are correct. The landing page uses this.$store.commit ("token", res.data.data) to report an error
.
main.js
import Vuex from "vuex"
Vue.use(Vuex)
login page
<div class="login_form">
<el-form :label-position="labelPosition" label-width="80px" :model="form">
<el-form-item>
<i class="account_icon"></i>
<el-input v-model="form.userName" placeholder=""></el-input>
</el-form-item>
<el-form-item prop="password">
<i class="password_icon"></i>
<el-input type="password" v-model="form.password" auto-complete="off" placeholder=""></el-input>
</el-form-item>
<div class="checkbox">
<input type="checkbox">
<span class="login_password"></span>
</div>
<div>
<button @click="onSubmit" :plain="true"></button>
</div>
<div class="login_embellish">
<i class="embellish_one"></i>
</div>
</el-form>
<i class="modifier_left"></i>
<i class="modifier_right"></i>
</div>
js
export default {
data() {
return {
labelPosition: "right",
form: {
userName: "",
password: ""
}
}
},
methods: {
onSubmit() {
let paramsData = {
username: this.form.userName,
password: this.form.password
};
this.$ajax.post(this.$api.Login, paramsData).then(res => {
if (res.status == 200) {
console.log("res", res);
this.$store.commit("token", res.data.data)
if(res.data.status == 401) {
this.$message.error(res.data.message);
}
}
})
.catch(err => {
console.log(err);
})
}
}
}