惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
CXSECURITY Database RSS Feed - CXSecurity.com
Stack Overflow Blog
Stack Overflow Blog
月光博客
月光博客
T
Threat Research - Cisco Blogs
小众软件
小众软件
有赞技术团队
有赞技术团队
酷 壳 – CoolShell
酷 壳 – CoolShell
Apple Machine Learning Research
Apple Machine Learning Research
C
Cyber Attacks, Cyber Crime and Cyber Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
T
Tailwind CSS Blog
Cisco Talos Blog
Cisco Talos Blog
V
V2EX
博客园 - 【当耐特】
C
Cybersecurity and Infrastructure Security Agency CISA
Hugging Face - Blog
Hugging Face - Blog
The Cloudflare Blog
The Last Watchdog
The Last Watchdog
Simon Willison's Weblog
Simon Willison's Weblog
T
Threatpost
S
Secure Thoughts
O
OpenAI News
P
Proofpoint News Feed
S
SegmentFault 最新的问题
Forbes - Security
Forbes - Security
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Application and Cybersecurity Blog
Application and Cybersecurity Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Last Week in AI
Last Week in AI
宝玉的分享
宝玉的分享
Scott Helme
Scott Helme
T
Tenable Blog
A
Arctic Wolf
L
LINUX DO - 热门话题
爱范儿
爱范儿
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
www.infosecurity-magazine.com
www.infosecurity-magazine.com
V
Visual Studio Blog
Hacker News: Ask HN
Hacker News: Ask HN
Hacker News - Newest:
Hacker News - Newest: "LLM"
腾讯CDC
博客园 - Franky
WordPress大学
WordPress大学
Know Your Adversary
Know Your Adversary
博客园_首页
雷峰网
雷峰网
IT之家
IT之家
PCI Perspectives
PCI Perspectives
L
LINUX DO - 最新话题
H
Heimdal Security Blog

博客园 - MvloveYouForever

flutter重新学习 uniapp简单移动端H5电脑端适配方案 添加ssh后,ssh-rsa fatal: Could not read git合并提交 cordova打印插件备注 H5开发类似rpx实现方法 maven仓库地址 idea与其他软件激活办法 linux常用命令总结 Command line is too long mysql安装教程备份 mybatis-plus 条件参数说明 关于打包electron应用 关于spring unicloud短信不能用 关于mybatis 关于maven vue2 和 vue3的区别 父子组件v-modle,vue2和vue3的区别
Vue3知识点
MvloveYouForever · 2024-08-27 · via 博客园 - MvloveYouForever

1、ref和reactive的区别。

  ①  js中对ref定义的值读取、修改,需要加.value,可以用插件↓来简单使用

      ②  ref修改引用可以直接修改,react不能修改引用对象,只能使用 Object.assign修改对象内容

      ③  基本类型建议使用ref,若需要一个响应式对象且层级不深ref和reactive都可以。如果响应式对象层级比较深,推荐使用reactive。表单比较多、回显等使用reactive。

       因为一堆.value不太合适

2、toRefs接收一个reactive定义的对象、toRef单个属性去转换成ref

let person = reactive({name:'张三':age:18})

let {age,name} = toRefs(person)
// 此时 age、name为  响应式的

console.log(age.value)
// 修改 age.value +=1; person中的 age也同时发生变化
let age1 = toRef(person,'age')
// 此时age1是响应式的

congsole.log(age1.value)

3、computed有缓存、普通方法获取结果没缓存,页面用几次调几次

// 一般写法
let fullName = computed(()=>{
    return name1.value + name2.value;
})
// 支持修改计算属性的写法
let fullName = compuetd({
    get(){
        return name1.value + name2.value;
     },
     set(val) {
         let [str1,str2] = val.split('-');
        name1.value = str1;
        name2.value = str2;
     }
}) 

4、watch四种用法:1、ref所定义的数据 2、reactive定义的数据3、函数返回的值4、包含以上的数组 

// 监听ref基础数据并停止

let sum = ref(8);
let stopWatch = watch(sum,(newValue,oldValue)=>{
     if (newValue>10) {
       stopWatch(); // 停止监听 
    }
});


let person = ref({name:'张三',age:18});

// 只能监听到person对象的引用是否发生变化
watch(person,(newValue,oldVale)=>{
    
});

// 开启深度监听,这样直接可以监事 person的每个属性编号
//  immediate:true 首次给person赋值也能监听到
watch(person,(newValue,oldVale)=>{
    
},{deep:true,immediate:true});

let person2 = reactive({name:'李四',age:20});
// 监听reactive对象的数据,默认开启深度监视且无法自动关闭
watch(person2,(newValue,oldValue)=>{
   
});

监听对象的属性

// 监听函数返回的值
let person = ref({name:'张三',old:18,car:{c1:'奥迪',c2:'宝马'}});
watch(()=>person.name,(newValue,oldValue)=>{

});

// 监听属性值是对象时,要加深度监听才能监听到对象内容变化
watch(()=>person.car,()=>{},{deep:true});

5、watchEffect,立即会执行、并全自动监视相关条件(watch需要指定监听的属性、watchEffect不需要指定)

let temp = ref(0);
let height = ref(10);

watchEffect(()=>{
   if (temp.value>60||height>50) {
      // 触发了
   }
})

6、接口、泛型、自定义类型。 export type Persons = PersonInter[] 也可以.

 7、传 props