could anyone can give me a hint about reusable component input in vue 3? Like this in React:
Let say,
- use
<Input />reusable component in parent component
import { useState } from 'react';
import Input from './component/Input';
function Home() {
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const handleSubmit = (e) => {
e.preventDefault();
console.log(email, password);
}
return (
<form onSubmit={handleSubmit}>
<Input id="email" labelText="Email" value={email} onChange={e => setEmail(e.target.value)} />
<Input id="password" labelText="Password" value={password} onChange={e => setPassword(e.target.value)} />
<button type="submit">Login</button>
</form>
);
}
- here
<Input />component:
export default function Input(props) {
const { id, labelText, value, onChange } = props;
return (
<label htmlFor={id}>{labelText}<label>
<input id={id} value={value} onChange={onChange}>
);
}