|
@@ -0,0 +1,32 @@
|
|
|
+<template>
|
|
|
+ <div>
|
|
|
+ <p>我叫{{ obj.name }}今年{{ obj.age }}岁</p>
|
|
|
+ <button @click="changeName">修改名字</button>
|
|
|
+ <button @click="changePerson">换个人</button>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script lang="ts" setup>
|
|
|
+import {reactive} from 'vue';
|
|
|
+// 定义接口去约束对象类型
|
|
|
+
|
|
|
+interface Person {
|
|
|
+ name:string,
|
|
|
+ age: number
|
|
|
+}
|
|
|
+
|
|
|
+let obj:Person = reactive({
|
|
|
+ name:"图图",
|
|
|
+ age:3
|
|
|
+})
|
|
|
+console.log(obj)
|
|
|
+function changeName():void {
|
|
|
+ obj.name = '蜡笔小新'
|
|
|
+}
|
|
|
+function changePerson():void {
|
|
|
+ Object.assign(obj,{name:'喜羊羊',age:7})
|
|
|
+}
|
|
|
+</script>
|
|
|
+
|
|
|
+<style lang="scss" scoped>
|
|
|
+</style>
|