|
@@ -0,0 +1,38 @@
|
|
|
|
|
+<template>
|
|
|
|
|
+ <div>
|
|
|
|
|
+ <h1>watchEffect</h1>
|
|
|
|
|
+ <p>
|
|
|
|
|
+ 姓: <input type="text" v-model="firstName">
|
|
|
|
|
+ </p>
|
|
|
|
|
+ <p>
|
|
|
|
|
+ 名: <input type="text" v-model="lastName">
|
|
|
|
|
+ </p>
|
|
|
|
|
+ <p>
|
|
|
|
|
+ 全名:{{ fullName }}
|
|
|
|
|
+ </p>
|
|
|
|
|
+ </div>
|
|
|
|
|
+</template>
|
|
|
|
|
+
|
|
|
|
|
+<script lang="ts" setup>
|
|
|
|
|
+import {ref,watch,watchEffect} from "vue"
|
|
|
|
|
+let firstName = ref("");
|
|
|
|
|
+let lastName = ref("");
|
|
|
|
|
+// let user = ref({
|
|
|
|
|
+// firstName:"",
|
|
|
|
|
+// lastName:""
|
|
|
|
|
+// })
|
|
|
|
|
+let fullName = ref("");
|
|
|
|
|
+watchEffect(()=>{
|
|
|
|
|
+ console.log(fullName.value,firstName.value,lastName.value)
|
|
|
|
|
+ fullName.value = firstName.value + lastName.value;
|
|
|
|
|
+})
|
|
|
|
|
+// watch(firstName,(newValue,oldValue)=>{
|
|
|
|
|
+// fullName.value = newValue + lastName.value
|
|
|
|
|
+// })
|
|
|
|
|
+// watch(lastName,(newValue,oldValue)=>{
|
|
|
|
|
+// fullName.value = firstName.value + newValue
|
|
|
|
|
+// })
|
|
|
|
|
+</script>
|
|
|
|
|
+
|
|
|
|
|
+<style lang="scss" scoped>
|
|
|
|
|
+</style>
|