{"id":691,"date":"2023-05-08T22:03:13","date_gmt":"2023-05-08T14:03:13","guid":{"rendered":"http:\/\/gjweb.top\/?p=691"},"modified":"2023-05-08T22:03:14","modified_gmt":"2023-05-08T14:03:14","slug":"03-to%e5%85%a8%e5%ae%b6%e6%a1%b6-toref-torefs-toraw","status":"publish","type":"post","link":"https:\/\/gjweb.top\/?p=691","title":{"rendered":"03.to\u5168\u5bb6\u6876 toref \/ torefs \/ toRaw"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"toref\">toref<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>\u539f\u59cb\u6570\u636e\u4e0d\u4f1a\u66f4\u65b0\u89c6\u56fe\uff0c\u6570\u636e\u4f1a\u66f4\u65b0<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;template&gt;<br> &nbsp;&lt;div&gt;this is hello world&lt;\/div&gt;<br> &nbsp;&lt;h1&gt;{{ state }}&lt;\/h1&gt;<br> &nbsp;&lt;button @click=\"handelClick\"&gt;click&lt;\/button&gt;<br>&lt;\/template&gt;<br>&lt;script setup lang=\"ts\"&gt;<br>import {toRef} from \"vue\"<br>const user = {<br> &nbsp;name:\"zhangsan\"<br>}<br>const state = toRef(user,\"name\")<br>const handelClick = ()=&gt;{<br> &nbsp;state.value = \"lisi\"<br> &nbsp;console.log(state.value) \/\/ lisi \u89c6\u56fe\u4e0d\u4f1a\u66f4\u65b0<br>}<br>&lt;\/script&gt;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"torefs\">torefs<\/h2>\n\n\n\n<p>\u7528\u4e8e\u89e3\u6784 ref \u5bf9\u8c61<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;script setup lang=\"ts\"&gt;<br>import { reactive, toRefs } from 'vue'<br>const obj = reactive({<br> &nbsp; &nbsp;name:\"zhangsan\"<br>})<br>let {name} = toRefs(obj)<br>&lt;\/script&gt;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toraw\">toRaw<\/h2>\n\n\n\n<p>\u7528\u4e8e\u5c06 \u54cd\u5e94\u5f0f\uff08proxy\uff09\u5bf9\u8c61\u8f6c\u4e3a\u666e\u901a\u5bf9\u8c61<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;script setup lang=\"ts\"&gt;<br>import { reactive, toRaw } from 'vue'<br>const obj = reactive({<br>    name:\"zhangsan\"<br>})<br>const newObj = toRaw(obj)<br>&lt;\/script&gt;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>toref \u539f\u59cb\u6570\u636e\u4e0d\u4f1a\u66f4\u65b0\u89c6\u56fe\uff0c\u6570\u636e\u4f1a\u66f4\u65b0 torefs \u7528\u4e8e\u89e3\u6784 ref \u5bf9\u8c61 toRaw \u7528\u4e8e\u5c06 \u54cd\u5e94\u5f0f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[64],"tags":[],"class_list":["post-691","post","type-post","status-publish","format-standard","hentry","category-vue3"],"_links":{"self":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/691","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=691"}],"version-history":[{"count":1,"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/691\/revisions"}],"predecessor-version":[{"id":692,"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/691\/revisions\/692"}],"wp:attachment":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=691"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=691"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=691"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}