Vue의 계산 속성 Getter 및 setter

3101 단어 vue.js

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>get&settitle>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js">script>
head>
<body>
<div id="app">
    {{ fullName }}
div>
<script>
    let vm = new Vue({
        el:'#app',
        data:{
            firstName:'Quincy',
            lastName:'Cui'
        },
        computed:{
            fullName:{
                get:function () {
                    return this.firstName+' '+this.lastName
                },
                set:function (val) {
                    console.log(val);
                    let arr = val.split(' ');
                    this.firstName = arr[0];
                    this.lastName = arr[1];

                }
            }
        }
    })
script>
body>
html>

콘솔에서 값을 입력할 때 set을 가져옵니다 ~

좋은 웹페이지 즐겨찾기