<template>
<div>
<h3>name:{{ person.name }}</h3>
<h3>age:{{ person.age }}</h3>
<h3>薪资:{{ person.job.j1.salary }}K</h3>
<button @click="Modify">修改</button>
<button style="margin: 0 20px" @click="add1">涨薪</button>
<button @click="add2">涨年龄</button>
</div>
</template>
<script>
import { reactive, watch } from "vue";
export default {
setup() {
let person = reactive({
name: "李四",
age: 16,
job: {
j1: {
salary: 20,
},
},
});
function Modify() {
person.name = "张三";
person.age = 20;
}
function add1() {
person.job.j1.salary++;
}
function add2() {
person.age++;
}
return {
person,
Modify,
add1,
add2,
};
},
};
</script>
|