|
@@ -1,6 +1,10 @@
|
|
|
<template>
|
|
|
<div>
|
|
|
- <p>我叫{{ obj.name }}今年{{ obj.age }}岁,我喜欢{{ obj.color.c1 }}和{{ obj.color.c2 }}</p>
|
|
|
+ <p>
|
|
|
+ 我叫{{ obj.name }}今年{{ obj.age }}岁,我喜欢{{ obj.color.c1 }}和{{
|
|
|
+ obj.color.c2
|
|
|
+ }}
|
|
|
+ </p>
|
|
|
<button @click="changePart1">修改名字</button>
|
|
|
<button @click="changePart2">修改整体</button>
|
|
|
<button @click="changePart3">修改颜色一</button>
|
|
@@ -9,41 +13,40 @@
|
|
|
</template>
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
-import {ref,reactive} from "vue"
|
|
|
+import { ref, reactive } from "vue";
|
|
|
let obj = ref({
|
|
|
- name:'小明',
|
|
|
- age:10,
|
|
|
- color: {
|
|
|
- c1:"红色",
|
|
|
- c2:"黄色"
|
|
|
- }
|
|
|
-})
|
|
|
+ name: "小明",
|
|
|
+ age: 10,
|
|
|
+ color: {
|
|
|
+ c1: "红色",
|
|
|
+ c2: "黄色",
|
|
|
+ },
|
|
|
+});
|
|
|
function changePart1() {
|
|
|
- obj.value.name = '图图'
|
|
|
+ obj.value.name = "图图";
|
|
|
}
|
|
|
function changePart2() {
|
|
|
- obj.value = {
|
|
|
- name:'瑶一瑶',
|
|
|
- age: 4,
|
|
|
+ obj.value = {
|
|
|
+ name: "瑶一瑶",
|
|
|
+ age: 4,
|
|
|
color: {
|
|
|
- c1:"红色1",
|
|
|
- c2:"黄色2"
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
+ c1: "红色1",
|
|
|
+ c2: "黄色2",
|
|
|
+ },
|
|
|
+ };
|
|
|
}
|
|
|
function changePart3() {
|
|
|
- obj.value.color.c1 = '紫色'
|
|
|
+ obj.value.color.c1 = "紫色";
|
|
|
}
|
|
|
function changePart4() {
|
|
|
- // obj.value.color = {
|
|
|
- // c1:'red',
|
|
|
- // c2:'yellow'
|
|
|
- // }
|
|
|
- Object.assign(obj.value.color,{c1:'red',c2:'blue'})
|
|
|
-
|
|
|
+ // obj.value.color = {
|
|
|
+ // c1:'red',
|
|
|
+ // c2:'yellow'
|
|
|
+ // }
|
|
|
+ Object.assign(obj.value.color, { c1: "red", c2: "blue" });
|
|
|
}
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
</style>
|
|
|
+
|