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

推荐订阅源

Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
SegmentFault 最新的问题
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Attack and Defense Labs
Attack and Defense Labs
F
Full Disclosure
Vercel News
Vercel News
N
News | PayPal Newsroom
The GitHub Blog
The GitHub Blog
H
Hacker News: Front Page
H
Heimdal Security Blog
P
Privacy International News Feed
博客园 - 司徒正美
Google DeepMind News
Google DeepMind News
N
Netflix TechBlog - Medium
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Cisco Blogs
L
Lohrmann on Cybersecurity
D
Docker
Recent Announcements
Recent Announcements
Security Archives - TechRepublic
Security Archives - TechRepublic
人人都是产品经理
人人都是产品经理
C
CXSECURITY Database RSS Feed - CXSecurity.com
P
Proofpoint News Feed
T
Tailwind CSS Blog
C
Check Point Blog
博客园 - 叶小钗
Google Online Security Blog
Google Online Security Blog
Martin Fowler
Martin Fowler
Stack Overflow Blog
Stack Overflow Blog
博客园 - 聂微东
S
Secure Thoughts
博客园 - Franky
博客园_首页
阮一峰的网络日志
阮一峰的网络日志
P
Palo Alto Networks Blog
Latest news
Latest news
量子位
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 三生石上(FineUI控件)
The Cloudflare Blog
Last Week in AI
Last Week in AI
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Cyberwarzone
Cyberwarzone
小众软件
小众软件
Cisco Talos Blog
Cisco Talos Blog
Hacker News: Ask HN
Hacker News: Ask HN
T
Threatpost
T
Tenable Blog
P
Privacy & Cybersecurity Law Blog
WordPress大学
WordPress大学

博客园 - 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