我在学习 VueJS 时遇到了问题。我想将数据发送到Firebase,但它一直告诉我变量从未使用过。我在承诺中宣布它。
这是脚本:
methods: {
register: function() {
const info = {
email: this.email,
password: this.passOne,
displayName: this.displayName
};
if(!this.error) {
Firebase.auth()
.createUserWithEmailAndPassword(info.email, info.password)
.then(
userCredentials => {
this.$router.replace('meetings');
},
error => {
this.error = error.message;
}
);
}
}
},
这是错误:
error 'userCredentials' is defined but never used no-unused-vars
这是一个es-lint 错误。要解决:
if(!this.error) {
Firebase.auth()
.createUserWithEmailAndPassword(info.email, info.password)
.then(
() => {
this.$router.replace('meetings');
},
或者你也可以要求 es-lint 不要寻找下一行:
//es-lint-disable-next-line no-unused-vars
.then( userCredentials => {
this.$router.replace('meetings');
},
像下面这样替换$router.replace(...)
代码
this.$router.replace({ name: 'meetings', params: { credentials: userCredentials } })
希望它能解决您的问题。