In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you how to understand Refs and Ref in Vue3. The content is concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
The editor shares with you the corresponding questions about the data in Vue3. Let's give an example of this.
Vue.createApp ({template: `{nameObj.name}}`, setup () {const {reactive} = Vue const nameObj = reactive ({name:'lilei',age:18}) setTimeout (() = > {nameObj.name = 'hanmeimei'}, 2000) return {nameObj}) .mount (' # root')
At this time, we may think of the content about deconstruction assignment in es6. Can we get the internal name by deconstructing the nameObj in the above example, and then return the name directly? That is, to write the code like this.
Vue.createApp ({template: `{name}}`, setup () {const {reactive,toRefs} = Vue const nameObj = reactive ({name:'lilei',age:18}) let {name} = nameObj setTimeout (() = > {name.value = 'hanmeimei'}, 2000) return {name}}) .mount (' # root')
In the actual operation, we found that the content on the page did not become hanmeimei. At this time, we need to introduce another content in Vue3. We should modify the code like this in order to achieve the responsiveness of data and pages.
Vue.createApp ({template: `{name}}`, setup () {const {reactive,toRefs} = Vue const nameObj = reactive ({name:'lilei',age:18}) let {name} = toRefs (nameObj) setTimeout (() = > {name.value = 'hanmeimei'}, 2000) return {name}}) .mount (' # root')
Again, very similar to toRefs is toRef, where the code example looks like this
Vue.createApp ({template: `{age}}`, setup () {const {reactive,toRef} = Vue const nameObj = reactive ({name:'lilei'}) let age = toRef (nameObj,'age') setTimeout (() = > {age.value = 'hanmeimei'}) 2000) return {age}}) .mount ('# root') the above is how to understand Refs and Ref in Vue3 Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.