vite+ts+vue3知识点(toRef,toRefs,toRaw)-创新互联

toRef(只能修改响应式对象的值,适合单个属性操作)
import { toRef, reactive } from "vue";

let person = reactive({ name: "老天师", age: 123, like: "雷法" });

const toRefLike = toRef(person, "like");

const btn = () =>{
  toRefLike.value = "金光咒";
};
toRefs(只能修改响应式对象的值,适合多个属性解构)
import { toRefs, reactive } from "vue";

let person = reactive({ name: "老天师", age: 123, like: "雷法" });

const { name, age, like } = toRefs(person);

const btn = () =>{
  name.value = "天通道人";
  age.value = 108;
  like.value = "金光咒";
};
toRaw(将proxy响应式对象变为普通对象)
import { toRef, toRaw, toRefs, reactive } from "vue";

let person = reactive({ name: "老天师", age: 123, like: "雷法" });

const btn = () =>{
  console.log(person, toRaw(person)); 
  // Reactive{name: '老天师', age: 123, like: '雷法'}
};

你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧

创新互联于2013年成立,是专业互联网技术服务公司,拥有项目成都网站建设、成都做网站网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元尧都做网站,已为上家服务,为尧都各地企业和个人服务,联系电话:13518219792
文章标题:vite+ts+vue3知识点(toRef,toRefs,toRaw)-创新互联
地址分享:http://myzitong.com/article/cdeoho.html