Skip to content

Instantly share code, notes, and snippets.

@cursosdesarrolloweb
Created January 17, 2021 10:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cursosdesarrolloweb/a65e09959c079fa5ecc1e18fe2f57449 to your computer and use it in GitHub Desktop.
Save cursosdesarrolloweb/a65e09959c079fa5ecc1e18fe2f57449 to your computer and use it in GitHub Desktop.
<script type="text/jsx">
import { reactive, toRefs, defineComponent } from "vue";
const App = defineComponent({
setup() {
const form = reactive({
username: "",
password: ""
})
const formToRefs = toRefs(form)
return () => (
<>
<DynamicInput
placeholder="Username"
model={formToRefs.username}
styles={{ padding: "10px", backgroundColor: "#111", color: "#fff", fontWeight: "bold" }}
/>
<p>Model: {formToRefs.username.value}</p>
<DynamicInput
placeholder="Password"
type="password"
model={formToRefs.password}
styles={{ padding: "10px", backgroundColor: "#222", color: "#fff", fontWeight: "bold" }}
/>
<p>Model: {formToRefs.password.value}</p>
</>
);
},
});
export default App
const DynamicInput = ({model, placeholder, styles, type = "text"}) => (
<input style={styles} type={type} placeholder={placeholder} v-model={model.value} />
)
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment