[英]ts2339) Property phone does not exist on type '{}'
React-Router 接收代碼
import React from "react";
import { Mutation } from "react-apollo";
import { RouteComponentProps } from "react-router-dom";
import { toast } from "react-toastify";
import { LOG_USER_IN } from "../../sharedQueries.local";
import { verifyPhone, verifyPhoneVariables } from "../../types/api";
import VerifyPhonePresenter from "./VerifyPhonePresenter";
import { VERIFY_PHONE } from "./VerifyPhoneQueries";
interface IState {
verificationKey: string;
phoneNumber:string;
}
interface IProps extends RouteComponentProps<any> {}
class VerifyMutation extends Mutation<verifyPhone,
verifyPhoneVariables> {}
class VerifyPhoneContainer extends React.Component<IProps, IState> {
constructor(props: IProps) {
super(props);
if (!props.location.state) {
props.history.push("/");
}
debugger;
this.state = {
phoneNumber: props.location.state.phone,
verificationKey: ""
};
}
React-Router 發送代碼
import React from "react";
import { Mutation, MutationFn } from "react-apollo";
import { RouteComponentProps } from "react-router-dom";
import { toast } from "react-toastify";
import {
startPhoneVerification,
startPhoneVerificationVariables
} from "../../types/api";
import PhoneLoginPresenter from "./PhoneLoginPresenter";
import { PHONE_SIGN_IN } from "./PhoneQueries";
interface IState {
countryCode: string;
phoneNumber: string;
}
class PhoneSignInMutation extends Mutation<
startPhoneVerification,
startPhoneVerificationVariables
> {}
class PhoneLoginContainer extends React.Component<
RouteComponentProps<any>,
IState
> {
public phoneMutation: MutationFn;
public state = {
countryCode: "+82",
phoneNumber: ""
};
public render() {
const { history } = this.props;
const { countryCode, phoneNumber } = this.state;
return (
<PhoneSignInMutation
mutation={PHONE_SIGN_IN}
variables={{
phoneNumber: `${countryCode}${phoneNumber}`
}}
onCompleted={data => {
const { StartPhoneVerification } = data;
const phone = `${countryCode}${phoneNumber}`;
if (StartPhoneVerification.ok) {
toast.success("SMS Sent! Redirecting you...");
setTimeout(() => {
history.push({
pathname: "/verify-phone",
state: {
phone
}
});
}, 2000);
} else {
toast.error(StartPhoneVerification.error);
}
}}
>
{(phoneMutation, { loading }) => {
this.phoneMutation = phoneMutation;
return (
<PhoneLoginPresenter
countryCode={countryCode}
phoneNumber={phoneNumber}
onInputChange={this.onInputChange}
onSubmit={this.onSubmit}
loading={loading}
/>
);
}}
</PhoneSignInMutation>
);
}
編譯失敗。 類型“{}”上不存在屬性“電話”。
請讓我知道為什么會發生錯誤。
我要用我的手機發短信和驗證。
但是,將電話號碼從上一頁移交到下一頁時,會出現以下錯誤。
我正在使用翻譯,因為我的英語不好。
我解決了
if (!props.location.state) {
props.history.push("/");
}
const {
location: { state }
} = props;
let phoneNumber = "";
if (state) {
phoneNumber = state.phone;
} else {
phoneNumber = "";
}
this.state = {
phoneNumber,
verificationKey: ""
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.