|
|
@@ -0,0 +1,52 @@
|
|
|
+<template>
|
|
|
+ <div>
|
|
|
+ <h1>计算属性</h1>
|
|
|
+ <p>姓: <input type="text" v-model="firstName"></p>
|
|
|
+ <p>名: <input type="text" v-model="lastName"></p>
|
|
|
+ <h1>全名:{{ fullName }}</h1>
|
|
|
+ <h1>全名:{{ fullName}}</h1>
|
|
|
+ <h1>全名:{{ fullName}}</h1>
|
|
|
+ <h1>全名:{{ fullName}}</h1>
|
|
|
+ <h1>全名:{{ fullName}}</h1>
|
|
|
+ <h1>全名:{{ fullName}}</h1>
|
|
|
+ <h1>全名:{{ fullName}}</h1>
|
|
|
+ <h1>全名:{{ fullName}}</h1>
|
|
|
+ <h1>全名:{{ fullName}}</h1>
|
|
|
+ <h1>全名:{{ fullName}}</h1>
|
|
|
+ <h1>全名:{{ fullName}}</h1>
|
|
|
+ <button @click="changeName">修改名字</button>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script lang="ts" setup>
|
|
|
+import {ref, computed} from "vue"
|
|
|
+let firstName = ref("胡");
|
|
|
+let lastName = ref("图图");
|
|
|
+
|
|
|
+const init = () => {
|
|
|
+ console.log("!")
|
|
|
+ return firstName.value + lastName.value
|
|
|
+}
|
|
|
+
|
|
|
+// 获取
|
|
|
+// let fullName = computed(()=>{
|
|
|
+// return firstName.value + lastName.value
|
|
|
+// })
|
|
|
+
|
|
|
+let fullName = computed({
|
|
|
+ get() {
|
|
|
+ console.log("?")
|
|
|
+ return firstName.value + lastName.value
|
|
|
+ },
|
|
|
+ set(val) {
|
|
|
+ firstName.value = val.slice(0,1);
|
|
|
+ lastName.value = val.substring(1,3);
|
|
|
+ }
|
|
|
+})
|
|
|
+function changeName() {
|
|
|
+ fullName.value = '喜羊羊'
|
|
|
+}
|
|
|
+</script>
|
|
|
+
|
|
|
+<style lang="scss" scoped>
|
|
|
+</style>
|