我想实现一个登录方法。我的代码是:
login() {
let user = {
email: this.email,
password: this.password
};
this.$store.dispatch('auth/login', user)
console.log(this.$store.getters['auth/getAuthError'])
},
Run Code Online (Sandbox Code Playgroud)
我到达商店并发送登录操作的地方。
商店中的操作如下所示:
login(vuexContext, user) {
return axios.post('http://localhost:8000/api/user/login', user)
.then(res => {
vuexContext.commit('setToken', res.data.token)
vuexContext.commit('setUser', res.data, {root: true})
localStorage.setItem('token', res.data.token)
Cookie.set('token', res.data.token )
this.$router.push('/')
}).catch(err => {
vuexContext.commit('setAuthError', err.response.data)
})
},
Run Code Online (Sandbox Code Playgroud)
在 catch 块中,如果发生错误,我会更新状态并将authError属性设置为我得到的错误。
我的问题是,在登录方法中,该console.log语句在动作实际完成之前执行,因此authError属性是尚未设置的状态。如何解决这个问题?
我正在开发 vscode 扩展..我想获取对整个文档的光标位置引用,例如,如果我有以下 html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<|body>
<div>
<p>Hello World</p>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
并且cursur位于body标签内(上面代码中符号的位置|),我想要的结果是178,如果你从头开始计算文档中的所有字符(包括空格),它就是字符的索引。
我试过这段代码
const position = editor.selection.active;
console.log(position);
Run Code Online (Sandbox Code Playgroud)
但它给出了该行以及该行中角色的位置,这不是我需要的。
有什么办法可以得到想要的输出吗?