Vue 计算属性set和get
<template>
<div class="hello">
测试1:<input type="text" v-model="demoData1">
测试2:<input type="text" v-model="demoData2">
测试3:<input type="text" v-model="demoData3">
</div>
</template>
<script>
export default {
name: 'HelloWorld',
computed: {
demoData3: {
get: function () {
console.log('111')
return this.demoData1
},
set: function (val) {
console.log('222')
this.demoData1 = val
}
}
},
data () {
return {
demoData1: '',
demoData2: ''
}
}
}
</script>
改变demoData3:
改变demoData1: