Last active
April 17, 2024 12:09
-
-
Save Kcko/ec6fc2a3780f695672d3a0ec9dec4215 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script setup> | |
import { ref, watch, toRefs } from 'vue' | |
const props = defineProps({ | |
test: String | |
}) | |
let refTest = ref(props.test) | |
const { test: testToRefs } = toRefs(props) | |
watch(() => props.test, (newValue) => { | |
refTest.value = newValue | |
}) | |
</script> | |
<template> | |
<div> | |
All ways how to have reactive props ... | |
<hr /> | |
child: <br /> | |
<hr /> | |
test -> {{ test }} <br /> | |
testToRefs -> {{ testToRefs }} <br /> | |
$props.test -> {{ $props.test }} <br /> | |
refTest-> {{ refTest }} <br /> | |
</div> | |
</template> | |
<!-- | |
after 3 seconds | |
test -> two | |
testToRefs -> two | |
$props.test -> two | |
refTest-> two | |
--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script setup> | |
import Child from './Child.vue' | |
import { ref } from 'vue' | |
const test = ref('one') | |
setTimeout(() => { | |
test.value = 'two' | |
}, 3000) | |
</script> | |
<template> | |
<h1>Parent</h1> | |
<Child :test="test"/> | |
</template> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment