Vue之计算属性getter和setter


<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获取到~

你可能感兴趣的:(vue.js)