Writing in the front

Good evening, friends. ToRef function was used today, so let’s talk about it briefly today.

Define reactive data:

ToRef is a function that converts a property of a responsive object into a single responsive data with associated values.

Sample code:

<template> <div> <div> Response to data </div> <hr> <! - < div > {{obj. MSG}} < / div > -- > < div > {{MSG}} < / div > < div > {{info}} < / div > < div > < button @ click = 'handleClick' > click < / button > </div> </div> </template> <script> import { reactive, toRef } from 'vue' export default { name: 'App', setup () {// Request: obj = reactive({MSG: 'hello', info: Const MSG = toRef(obj, 'MSG ') const info = toRef(obj,' MSG ') 'info') const handleClick = () => {obj. MSG = 'nihao' obj. Info = 'coniqiwa'} msg, info, handleClick } } } </script> <style lang="less"> </style>Copy the code

Write in the last

The toRef method can extract a single attribute from an object and ensure responsiveness

That’s all for today. See you next time վ’ᴗ’ ի~