我是 vue 新手,正在尝试创建一个视图,在有人注册后使用代码验证电子邮件。我目前只有视图,没有任何内容连接到电子邮件或生成代码。我在这个 vue 项目中使用 pug、typescript 和 scss。我知道这个问题通常是因为拼写错误,但我找不到。想法?
.vue 文件:
.Verify
.Verify__focus
.Verify__title Verify Your Email
.Verify__form
.Verify__field
va-input.Verify__textInput(
type="text",
name="verificationCode",
placeholder="Verification Code",
v-model="text",
@keyup.enter="verifyUser()"
)
template(v-slot:prependInner="")
va-icon(name="check_circle")
.Login__buttonRow
va-button.Login__submitButton(@click="verifyUser") Verify
.ts 文件:
import { Ref } from "vue";
import { useApolloClient } from "@vue/apollo-composable";
import { ValidatedUser } from "@/models";
import { gql } from "graphql-tag";
const query = gql`
query Verify($input: Verify) {
Verify(input: $input) {
__typename
token
user {
email
id
}
}
}
`;
/**
* Retrive apollo client and provide useVerify
* function to validate input and execute Verify process.
*
* @param verificationCode - reactively wrapped email address of the user signing up.
* @returns useVerify composition functionality.
*/
export default function useVerify(verificationCode: Ref): {
verifyUser: () => Promise;
} {
const { resolveClient } = useApolloClient();
/**
* Execute the Verify process for the given verification code.
*/
async function verifyUser(): Promise {
if (verificationCode.value !== "123456") {
return;
}
else{
console.log("worked");
//TODO: auth here
}
const client = resolveClient();
const variables = {
input: { username: verificationCode.value },
};
const response = await client.query({ query, variables });
const validatedUser: ValidatedUser = response.data.Verify;
console.log("USER:", validatedUser);
console.log("verificationCode: ", variables);
}
return { verifyUser };
}
提前致谢!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
似乎这一行触发了模板中的错误
.... .Verify__field va-input.Verify__textInput( type="text", name="verificationCode", placeholder="Verification Code", v-model="text", //原因是您在设置函数中没有返回名为
text的变量function setup() { const verificationCode = ref(""); const { verifyUser } = useVerify(verificationCode); return { verificationCode, verifyUser, //no text property here }; }您可能需要定义这样的文本属性
function setup() { const verificationCode = ref(""); const { verifyUser } = useVerify(verificationCode); const text = ref(""); return { verificationCode, verifyUser, text, }; }