vue学习

This commit is contained in:
yingfeng.ai 2024-10-31 10:43:01 +08:00
parent 812e2b55e4
commit be69ea3ba4

View File

@ -0,0 +1,45 @@
<template>
<div class="person">
<h2>{{ car.price }}-----{{ car.brand }}</h2>
<button @click="changeCartoRefs">修改汽车价格和名字</button>
<button @click="changeCartoRef">修改汽车价格和名字</button>
</div>
</template>
<script setup>
import { reactive, toRefs, toRef } from "vue";
// car
let car = reactive({ brand: 'byd', price: 10000000 });
// 使 toRefs car
let { brand, price } = toRefs(car);
// 使 toRef car
let nl = toRef(car, 'brand');
//
function changeCartoRefs() {
// brand price 使 .value
brand.value = 'kdlk';
price.value = 20000000;
}
function changeCartoRef() {
// brand 使 .value
nl.value = '44444444'
}
</script>
<style scoped>
.person {
background-color: antiquewhite;
box-shadow: 0 0 10px;
}
button {
margin: 5px;
}
</style>